123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176 |
- //
- // TenantCreateGroupBodyView.m
- // KulexiuForTeacher
- //
- // Created by 王智 on 2023/9/14.
- //
- #import "TenantCreateGroupBodyView.h"
- #import "TenantStuModel.h"
- #import "TenantCreateStuView.h"
- @interface TenantCreateGroupBodyView ()<UITextFieldDelegate, UITextViewDelegate>
- @property (nonatomic, copy) AddGroupMemberCallback callback;
- @property (weak, nonatomic) IBOutlet UIView *memberView;
- @property (weak, nonatomic) IBOutlet UIImageView *fansChooseImage;
- @property (weak, nonatomic) IBOutlet UIImageView *tenantChooseImage;
- @property (weak, nonatomic) IBOutlet UIView *memberDisplayView;
- @property (weak, nonatomic) IBOutlet NSLayoutConstraint *memberDisplayHeigh;
- @property (weak, nonatomic) IBOutlet UILabel *tipsLabel;
- @property (nonatomic, strong) UIScrollView *scrollView;
- @end
- @implementation TenantCreateGroupBodyView
- - (void)awakeFromNib {
- [super awakeFromNib];
- self.isFansGroup = YES;
- self.nameField.delegate = self;
- self.inputView.delegate = self;
- [self.memberDisplayView addSubview:self.scrollView];
- [self.scrollView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.right.top.bottom.mas_equalTo(self.memberDisplayView);
- }];
- }
- + (instancetype)shareInstance {
- TenantCreateGroupBodyView *view = [[[NSBundle mainBundle] loadNibNamed:@"TenantCreateGroupBodyView" owner:nil options:nil] firstObject];
- return view;
- }
- - (void)refreshMemberView:(NSMutableArray *)array {
- if (array.count > 0) {
- self.memberDisplayHeigh.constant = 94.0f;
- }
- else {
- self.memberDisplayHeigh.constant = 0;
- }
- [self.scrollView removeAllSubViews];
- NSInteger maxCount = IS_IPAD ? 9 : 5;
- CGFloat width = (KPortraitWidth - 28) / maxCount;
- CGFloat xPosition = 0.0f;
- for (NSInteger index = 0; index < array.count; index++) {
- xPosition = index * width;
- CGRect frame = CGRectMake(xPosition, 0, width, 81);
- TenantCreateStuView *view = [TenantCreateStuView shareInstance];
- view.frame = frame;
- TenantStuModel *model = array[index];
- [view configWithSource:model];
- [self.scrollView addSubview:view];
- }
- self.scrollView.contentSize = CGSizeMake(width * array.count, 94.0f);
- }
- - (void)addGroupMember:(AddGroupMemberCallback)callback {
- if (callback) {
- self.callback = callback;
- }
- }
- - (IBAction)addMemberAction:(id)sender {
- if (self.callback) {
- self.callback(GROUPADDTYPE_ADDMEMBER);
- }
- }
- - (IBAction)chooseFans:(id)sender {
- self.isFansGroup = YES;
- }
- - (IBAction)chooseTenant:(id)sender {
- self.isFansGroup = NO;
- }
- - (void)setIsFansGroup:(BOOL)isFansGroup {
- _isFansGroup = isFansGroup;
- if (isFansGroup) {
- [self.fansChooseImage setImage:[UIImage imageNamed:@"tenant_group_choose"]];
- [self.tenantChooseImage setImage:[UIImage imageNamed:@"tenant_group_unchoose"]];
- }
- else {
- [self.fansChooseImage setImage:[UIImage imageNamed:@"tenant_group_unchoose"]];
- [self.tenantChooseImage setImage:[UIImage imageNamed:@"tenant_group_choose"]];
- }
- if (isFansGroup) {
- self.memberView.hidden = YES;
- }
- else {
- self.memberView.hidden = NO;
- }
- GROUPADDTYPE type = isFansGroup ? GROUPADDTYPE_FANS : GROUPADDTYPE_TENANT;
- if (self.callback) {
- self.callback(type);
- }
- }
- #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 {
- // 输入控制
- NSString *newString = [textView.text stringByReplacingCharactersInRange:range withString:text];
- if (newString.length > 500) {
- return NO;
- }
- 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;
- }
- // 输入控制
- NSString *newString = [textField.text stringByReplacingCharactersInRange:range withString:string];
- if (newString.length > 50) {
- return NO;
- }
- return YES;
- }
- - (UIScrollView *)scrollView {
- if (!_scrollView) {
- _scrollView = [[UIScrollView alloc] initWithFrame:CGRectZero];
- }
- return _scrollView;
- }
- /*
- // Only override drawRect: if you perform custom drawing.
- // An empty implementation adversely affects performance during animation.
- - (void)drawRect:(CGRect)rect {
- // Drawing code
- }
- */
- @end
|