// // ChatBatchView.m // AIIM // // Created by qitewei on 2025/5/10. // #import "ChatBatchView.h" @interface ChatBatchView() @property (nonatomic, strong) UILabel * closeTitle; @property (nonatomic, strong) UILabel * multipleTitle; @property (nonatomic, strong) UILabel * singleTitle; @property (nonatomic, strong) UILabel * deleteTitle; @property (nonatomic, copy) NSArray * images; @property (nonatomic, strong) NSMutableArray * labels; @end @implementation ChatBatchView - (instancetype)initWithFrame:(CGRect)frame{ if (self=[super initWithFrame:frame]) { self.backgroundColor = UIColor.whiteColor; [self configUI]; } return self; } - (void)configUI{ NSMutableArray * buttons = [NSMutableArray array]; for (NSString * imageName in self.images) { UIButton * button = [UIButton buttonWithType:UIButtonTypeCustom]; button.tag = [self.images indexOfObject:imageName]+3000; [button setImage:kImageMake(imageName) forState:UIControlStateNormal]; [button addTarget:self action:@selector(batchButtonClicked:) forControlEvents:UIControlEventTouchUpInside]; [self addSubview:button]; [buttons addObject:button]; [button mas_makeConstraints:^(MASConstraintMaker *make) { make.height.mas_equalTo(40); make.top.mas_equalTo(10); }]; } [buttons mas_distributeViewsAlongAxis:MASAxisTypeHorizontal withFixedSpacing:(SCREEN_WIDTH-220)/3.f leadSpacing:30 tailSpacing:30]; for (int i = 0; i < self.labels.count; i++) { UIButton * button = buttons[i]; UILabel * label = self.labels[i]; [self addSubview:label]; [label mas_makeConstraints:^(MASConstraintMaker *make) { make.height.mas_equalTo(16); make.top.mas_equalTo(button.mas_bottom).offset(8); make.centerX.mas_equalTo(button.mas_centerX); }]; } } #pragma mark event - (void)batchButtonClicked:(UIButton *)sender{ NSInteger index = sender.tag-3000; if (self.indexOfBatchClicked) { self.indexOfBatchClicked(index); } } #pragma mark lazy - (UILabel *)closeTitle{ if (!_closeTitle) { _closeTitle = [[UILabel alloc] init]; _closeTitle.text = @"取消"; _closeTitle.textColor = UIColor.blackColor; _closeTitle.textAlignment = NSTextAlignmentCenter; _closeTitle.font = SYSFONT(16); } return _closeTitle; } - (UILabel *)multipleTitle{ if (!_multipleTitle) { _multipleTitle = [[UILabel alloc] init]; _multipleTitle.text = @"合并转发"; _multipleTitle.textColor = UIColor.blackColor; _multipleTitle.textAlignment = NSTextAlignmentCenter; _multipleTitle.font = SYSFONT(16); } return _multipleTitle; } - (UILabel *)singleTitle{ if (!_singleTitle) { _singleTitle = [[UILabel alloc] init]; _singleTitle.text = @"逐条转发"; _singleTitle.textColor = UIColor.blackColor; _singleTitle.textAlignment = NSTextAlignmentCenter; _singleTitle.font = SYSFONT(16); } return _singleTitle; } - (UILabel *)deleteTitle{ if (!_deleteTitle) { _deleteTitle = [[UILabel alloc] init]; _deleteTitle.text = @"删除"; _deleteTitle.textColor = UIColor.blackColor; _deleteTitle.textAlignment = NSTextAlignmentCenter; _deleteTitle.font = SYSFONT(16); } return _deleteTitle; } - (NSArray *)images{ if (!_images) { _images = @[@"close",@"hebingzhuanfa",@"zhuanfa",@"shanchu"]; } return _images; } - (NSMutableArray *)labels{ if (!_labels) { _labels = [NSMutableArray arrayWithArray:@[self.closeTitle,self.multipleTitle,self.singleTitle,self.deleteTitle]]; } return _labels; } @end