TenantCreateGroupBodyView.m 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. //
  2. // TenantCreateGroupBodyView.m
  3. // KulexiuForTeacher
  4. //
  5. // Created by 王智 on 2023/9/14.
  6. //
  7. #import "TenantCreateGroupBodyView.h"
  8. #import "TenantStuModel.h"
  9. #import "TenantCreateStuView.h"
  10. @interface TenantCreateGroupBodyView ()<UITextFieldDelegate, UITextViewDelegate>
  11. @property (nonatomic, copy) AddGroupMemberCallback callback;
  12. @property (weak, nonatomic) IBOutlet UIView *memberView;
  13. @property (weak, nonatomic) IBOutlet UIImageView *fansChooseImage;
  14. @property (weak, nonatomic) IBOutlet UIImageView *tenantChooseImage;
  15. @property (weak, nonatomic) IBOutlet UIView *memberDisplayView;
  16. @property (weak, nonatomic) IBOutlet NSLayoutConstraint *memberDisplayHeigh;
  17. @property (weak, nonatomic) IBOutlet UILabel *tipsLabel;
  18. @property (nonatomic, strong) UIScrollView *scrollView;
  19. @end
  20. @implementation TenantCreateGroupBodyView
  21. - (void)awakeFromNib {
  22. [super awakeFromNib];
  23. self.isFansGroup = YES;
  24. self.nameField.delegate = self;
  25. self.inputView.delegate = self;
  26. [self.memberDisplayView addSubview:self.scrollView];
  27. [self.scrollView mas_makeConstraints:^(MASConstraintMaker *make) {
  28. make.left.right.top.bottom.mas_equalTo(self.memberDisplayView);
  29. }];
  30. }
  31. + (instancetype)shareInstance {
  32. TenantCreateGroupBodyView *view = [[[NSBundle mainBundle] loadNibNamed:@"TenantCreateGroupBodyView" owner:nil options:nil] firstObject];
  33. return view;
  34. }
  35. - (void)refreshMemberView:(NSMutableArray *)array {
  36. if (array.count > 0) {
  37. self.memberDisplayHeigh.constant = 94.0f;
  38. }
  39. else {
  40. self.memberDisplayHeigh.constant = 0;
  41. }
  42. [self.scrollView removeAllSubViews];
  43. NSInteger maxCount = IS_IPAD ? 9 : 5;
  44. CGFloat width = (KPortraitWidth - 28) / maxCount;
  45. CGFloat xPosition = 0.0f;
  46. for (NSInteger index = 0; index < array.count; index++) {
  47. xPosition = index * width;
  48. CGRect frame = CGRectMake(xPosition, 0, width, 81);
  49. TenantCreateStuView *view = [TenantCreateStuView shareInstance];
  50. view.frame = frame;
  51. TenantStuModel *model = array[index];
  52. [view configWithSource:model];
  53. [self.scrollView addSubview:view];
  54. }
  55. self.scrollView.contentSize = CGSizeMake(width * array.count, 94.0f);
  56. }
  57. - (void)addGroupMember:(AddGroupMemberCallback)callback {
  58. if (callback) {
  59. self.callback = callback;
  60. }
  61. }
  62. - (IBAction)addMemberAction:(id)sender {
  63. if (self.callback) {
  64. self.callback(GROUPADDTYPE_ADDMEMBER);
  65. }
  66. }
  67. - (IBAction)chooseFans:(id)sender {
  68. self.isFansGroup = YES;
  69. }
  70. - (IBAction)chooseTenant:(id)sender {
  71. self.isFansGroup = NO;
  72. }
  73. - (void)setIsFansGroup:(BOOL)isFansGroup {
  74. _isFansGroup = isFansGroup;
  75. if (isFansGroup) {
  76. [self.fansChooseImage setImage:[UIImage imageNamed:@"tenant_group_choose"]];
  77. [self.tenantChooseImage setImage:[UIImage imageNamed:@"tenant_group_unchoose"]];
  78. }
  79. else {
  80. [self.fansChooseImage setImage:[UIImage imageNamed:@"tenant_group_unchoose"]];
  81. [self.tenantChooseImage setImage:[UIImage imageNamed:@"tenant_group_choose"]];
  82. }
  83. if (isFansGroup) {
  84. self.memberView.hidden = YES;
  85. }
  86. else {
  87. self.memberView.hidden = NO;
  88. }
  89. GROUPADDTYPE type = isFansGroup ? GROUPADDTYPE_FANS : GROUPADDTYPE_TENANT;
  90. if (self.callback) {
  91. self.callback(type);
  92. }
  93. }
  94. #pragma mark ---- delegate
  95. - (void)textViewDidBeginEditing:(UITextView *)textView {
  96. self.tipsLabel.hidden = YES;
  97. }
  98. - (void)textViewDidEndEditing:(UITextView *)textView {
  99. if ([NSString isEmptyString:textView.text]) {
  100. self.tipsLabel.hidden = NO;
  101. }
  102. }
  103. - (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text {
  104. // 输入控制
  105. NSString *newString = [textView.text stringByReplacingCharactersInRange:range withString:text];
  106. if (newString.length > 500) {
  107. return NO;
  108. }
  109. return YES;
  110. }
  111. - (BOOL)textViewShouldEndEditing:(UITextView *)textView {
  112. [self endEditing:YES];
  113. return YES;
  114. }
  115. - (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
  116. [self endEditing:YES];
  117. }
  118. - (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string {
  119. if ([string isEqualToString:@"\n"]) {
  120. [self endEditing:YES];
  121. return YES;
  122. }
  123. // 输入控制
  124. NSString *newString = [textField.text stringByReplacingCharactersInRange:range withString:string];
  125. if (newString.length > 50) {
  126. return NO;
  127. }
  128. return YES;
  129. }
  130. - (UIScrollView *)scrollView {
  131. if (!_scrollView) {
  132. _scrollView = [[UIScrollView alloc] initWithFrame:CGRectZero];
  133. }
  134. return _scrollView;
  135. }
  136. /*
  137. // Only override drawRect: if you perform custom drawing.
  138. // An empty implementation adversely affects performance during animation.
  139. - (void)drawRect:(CGRect)rect {
  140. // Drawing code
  141. }
  142. */
  143. @end