CreateLiveBodyView.m 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. //
  2. // CreateLiveBodyView.m
  3. // KulexiuForTeacher
  4. //
  5. // Created by Kyle on 2022/3/30.
  6. //
  7. #import "CreateLiveBodyView.h"
  8. #import <KSToolLibrary/UIView+ExtensionForDotLine.h>
  9. @interface CreateLiveBodyView ()<UITextFieldDelegate,UITextViewDelegate>
  10. @property (weak, nonatomic) IBOutlet UITextField *titleField;
  11. @property (weak, nonatomic) IBOutlet UITextView *inputView;
  12. @property (weak, nonatomic) IBOutlet UILabel *tipsLabel;
  13. @property (weak, nonatomic) IBOutlet UILabel *countLabel;
  14. @property (weak, nonatomic) IBOutlet UIView *buttonBgView;
  15. @property (nonatomic, copy) CreateLiveCallback callback;
  16. @property (nonatomic, copy) ChooseLiveCoverCallback chooseCoverBlock;
  17. @end
  18. @implementation CreateLiveBodyView
  19. - (void)awakeFromNib {
  20. [super awakeFromNib];
  21. self.titleField.delegate = self;
  22. self.titleField.attributedPlaceholder = [[NSAttributedString alloc] initWithString:@"请输入直播标题" attributes:@{NSForegroundColorAttributeName:HexRGB(0xc1c1c1)}];
  23. self.inputView.delegate = self;
  24. [self.buttonBgView drawBoardDottedLine:1.0f length:4 space:4 cornerRadius:10.0f lineColor:HexRGB(0xe3e3e3)];
  25. }
  26. + (instancetype)shareInstance {
  27. CreateLiveBodyView *view = [[[NSBundle mainBundle] loadNibNamed:@"CreateLiveBodyView" owner:nil options:nil] firstObject];
  28. return view;
  29. }
  30. - (void)createSureCallback:(CreateLiveCallback)callback {
  31. if (callback) {
  32. self.callback = callback;
  33. }
  34. }
  35. - (void)chooseCoverCallback:(ChooseLiveCoverCallback)callback {
  36. if (callback) {
  37. self.chooseCoverBlock = callback;
  38. }
  39. }
  40. - (IBAction)chooseCover:(id)sender {
  41. if (self.chooseCoverBlock) {
  42. self.chooseCoverBlock();
  43. }
  44. }
  45. - (IBAction)sureAction:(id)sender {
  46. [self endEditing:YES];
  47. if ([NSString isEmptyString:self.titleField.text]) {
  48. [LOADING_MANAGER MBShowAUTOHidingInWindow:@"请输入直播标题"];
  49. return;
  50. }
  51. if ([NSString isEmptyString:self.inputView.text]) {
  52. [LOADING_MANAGER MBShowAUTOHidingInWindow:@"请输入直播内容"];
  53. return;
  54. }
  55. if ([self.timeLabel.text isEqualToString:@"请选择直播时长"]) {
  56. [LOADING_MANAGER MBShowAUTOHidingInWindow:@"请选择直播时长"];
  57. return;
  58. }
  59. if (self.callback) {
  60. self.callback(NO,self.titleField.text, self.inputView.text);
  61. }
  62. }
  63. - (IBAction)chooseTime:(id)sender {
  64. [self endEditing:YES];
  65. if (self.callback) {
  66. self.callback(YES, @"", @"");
  67. }
  68. }
  69. #pragma mark ---- delegate
  70. - (void)textViewDidBeginEditing:(UITextView *)textView {
  71. self.tipsLabel.hidden = YES;
  72. }
  73. - (void)textViewDidEndEditing:(UITextView *)textView {
  74. if ([NSString isEmptyString:textView.text]) {
  75. self.tipsLabel.hidden = NO;
  76. }
  77. }
  78. - (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text {
  79. if ([text isEqualToString:@"\n"]) {
  80. [self endEditing:YES];
  81. return YES;
  82. }
  83. // 长度判断
  84. // 输入控制
  85. NSString *newString = [textView.text stringByReplacingCharactersInRange:range withString:text];
  86. if (newString.length > 200) {
  87. return NO;
  88. }
  89. self.countLabel.text = [NSString stringWithFormat:@"%zd/200",newString.length];
  90. return YES;
  91. }
  92. - (BOOL)textViewShouldEndEditing:(UITextView *)textView {
  93. [self endEditing:YES];
  94. return YES;
  95. }
  96. - (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
  97. [self endEditing:YES];
  98. }
  99. - (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string {
  100. if ([string isEqualToString:@"\n"]) {
  101. [self endEditing:YES];
  102. return YES;
  103. }
  104. return YES;
  105. }
  106. /*
  107. // Only override drawRect: if you perform custom drawing.
  108. // An empty implementation adversely affects performance during animation.
  109. - (void)drawRect:(CGRect)rect {
  110. // Drawing code
  111. }
  112. */
  113. @end