123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140 |
- //
- // CreateLiveBodyView.m
- // KulexiuForTeacher
- //
- // Created by Kyle on 2022/3/30.
- //
- #import "CreateLiveBodyView.h"
- #import <KSToolLibrary/UIView+ExtensionForDotLine.h>
- @interface CreateLiveBodyView ()<UITextFieldDelegate,UITextViewDelegate>
- @property (weak, nonatomic) IBOutlet UITextField *titleField;
- @property (weak, nonatomic) IBOutlet UITextView *inputView;
- @property (weak, nonatomic) IBOutlet UILabel *tipsLabel;
- @property (weak, nonatomic) IBOutlet UILabel *countLabel;
- @property (weak, nonatomic) IBOutlet UIView *buttonBgView;
- @property (nonatomic, copy) CreateLiveCallback callback;
- @property (nonatomic, copy) ChooseLiveCoverCallback chooseCoverBlock;
- @end
- @implementation CreateLiveBodyView
- - (void)awakeFromNib {
- [super awakeFromNib];
- self.titleField.delegate = self;
- self.titleField.attributedPlaceholder = [[NSAttributedString alloc] initWithString:@"请输入直播标题" attributes:@{NSForegroundColorAttributeName:HexRGB(0xc1c1c1)}];
- self.inputView.delegate = self;
- [self.buttonBgView drawBoardDottedLine:1.0f length:4 space:4 cornerRadius:10.0f lineColor:HexRGB(0xe3e3e3)];
- }
- + (instancetype)shareInstance {
- CreateLiveBodyView *view = [[[NSBundle mainBundle] loadNibNamed:@"CreateLiveBodyView" owner:nil options:nil] firstObject];
- return view;
- }
- - (void)createSureCallback:(CreateLiveCallback)callback {
- if (callback) {
- self.callback = callback;
- }
- }
- - (void)chooseCoverCallback:(ChooseLiveCoverCallback)callback {
- if (callback) {
- self.chooseCoverBlock = callback;
- }
- }
- - (IBAction)chooseCover:(id)sender {
- if (self.chooseCoverBlock) {
- self.chooseCoverBlock();
- }
- }
- - (IBAction)sureAction:(id)sender {
- [self endEditing:YES];
- if ([NSString isEmptyString:self.titleField.text]) {
- [LOADING_MANAGER MBShowAUTOHidingInWindow:@"请输入直播标题"];
- return;
- }
- if ([NSString isEmptyString:self.inputView.text]) {
- [LOADING_MANAGER MBShowAUTOHidingInWindow:@"请输入直播内容"];
- return;
- }
- if ([self.timeLabel.text isEqualToString:@"请选择直播时长"]) {
- [LOADING_MANAGER MBShowAUTOHidingInWindow:@"请选择直播时长"];
- return;
- }
- if (self.callback) {
- self.callback(NO,self.titleField.text, self.inputView.text);
- }
- }
- - (IBAction)chooseTime:(id)sender {
- [self endEditing:YES];
- if (self.callback) {
- self.callback(YES, @"", @"");
- }
- }
- #pragma mark ---- delegate
- - (void)textViewDidBeginEditing:(UITextView *)textView {
- self.tipsLabel.hidden = YES;
- }
- - (void)textViewDidEndEditing:(UITextView *)textView {
- if ([NSString isEmptyString:textView.text]) {
- self.tipsLabel.hidden = NO;
- }
- }
- - (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text {
- if ([text isEqualToString:@"\n"]) {
- [self endEditing:YES];
- return YES;
- }
- // 长度判断
- // 输入控制
- NSString *newString = [textView.text stringByReplacingCharactersInRange:range withString:text];
- if (newString.length > 200) {
- return NO;
- }
- self.countLabel.text = [NSString stringWithFormat:@"%zd/200",newString.length];
-
- return YES;
- }
- - (BOOL)textViewShouldEndEditing:(UITextView *)textView {
- [self endEditing:YES];
- return YES;
- }
- - (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
- [self endEditing:YES];
- }
- - (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string {
- if ([string isEqualToString:@"\n"]) {
- [self endEditing:YES];
- return YES;
- }
- return YES;
- }
- /*
- // Only override drawRect: if you perform custom drawing.
- // An empty implementation adversely affects performance during animation.
- - (void)drawRect:(CGRect)rect {
- // Drawing code
- }
- */
- @end
|