NSString *advantageStr;//接收亮点标签
NSArray *JobTagArry;//从后台返回的标签
NSMutableArray *selectArr;//接收点击的btn
进去没有标签 获取后台给的标签
CGFloat w = ([UIScreen mainScreen].bounds.size.width-20) / 3-10;
CGFloat h = 30;
CGFloat margin = 10;
for (NSInteger i = 0; i < JobTagArry.count; i++) {
UIButton *button = [[UIButton alloc] init];
[cell3.linghtspotagScrollView addSubview:button];
button.tag = i + 100;
[button setTitle:((SJFourthVCModel *)(JobTagArry[i])).ra_name forState:UIControlStateNormal];
[button setTitleColor:[UIColor lightGrayColor] forState:UIControlStateNormal];
[button setTitleColor:[UIColor whiteColor] forState:UIControlStateSelected];
button.titleLabel.font = [UIFont systemFontOfSize:12];
button.layer.cornerRadius = 15;
button.layer.masksToBounds = YES;
button.layer.borderColor = TABLEVIEWBCOLOR.CGColor;
button.layer.borderWidth = 1;
//[button setImage:[UIImage imageNamed:@"灰加"] forState:UIControlStateNormal];
button.backgroundColor = TABLEVIEWBCOLOR;
CGFloat x = ((button.tag - 100) % 3) * (w + margin) + margin;
CGFloat y = ((button.tag - 100) / 3) * (h + margin) + margin;
button.frame = CGRectMake(x, y, w, h);
[button addTarget:self action:@selector(selectTitle:) forControlEvents:UIControlEventTouchUpInside];
cell3.linghtspotagScrollView.contentSize = CGSizeMake(3 * w + 5 * margin + 0.5 * w, 0);
button.selected = NO;
if ([selectArr containsObject:[NSString stringWithFormat:@"%ld",i+100]]) {
[button setBackgroundColor:main_Color];
button.selected = YES;
}
}
#pragma mark -------标签点击
- (void)selectTitle:(UIButton *)button{
NSIndexPath *indexPath = [NSIndexPath indexPathForRow:0 inSection:4];
SJLightspotTagTableViewCell*cell = [_thirhTableView cellForRowAtIndexPath:indexPath];
NSLog(@"%lu",(unsigned long)selectArr.count);
if (!button.selected) {
if (selectArr.count < 3) {
[button setBackgroundColor:main_Color];
[selectArr addObject:[NSString stringWithFormat:@"%ld",button.tag]];
}else{
NSString *indexStr = selectArr[0];
NSInteger index = [indexStr integerValue];
UIButton *btn = [cell.contentView viewWithTag:index];
[btn setBackgroundColor:TABLEVIEWBCOLOR];
btn.selected = NO;
[selectArr removeObject:[NSString stringWithFormat:@"%ld",btn.tag]];
[button setBackgroundColor:main_Color];
[selectArr addObject:[NSString stringWithFormat:@"%ld",button.tag]];
}
}else{
if ([selectArr containsObject:[NSString stringWithFormat:@"%ld",button.tag]]) {
[button setBackgroundColor:TABLEVIEWBCOLOR];
[selectArr removeObject:[NSString stringWithFormat:@"%ld",button.tag]];
}
}
button.selected = !button.selected;
NSMutableString *str = [NSMutableString string];
for (id obj in cell.linghtspotagScrollView.subviews) {
if ([obj isKindOfClass:[UIButton class]]) {
UIButton* theButton = (UIButton*)obj;
if (theButton.selected == YES) {
NSLog(@"%@",theButton.titleLabel.text);
[str appendString:theButton.titleLabel.text];
[str appendString:@","];
NSLog(@"%@",str);
}
}
}
advantageStr =[NSString stringWithFormat:@"%@",str];
NSLog(@"%@",advantageStr);
}
还有一种 是有标签的
加上这一段
进去 先获取到 点击的btn
NSMutableArray*skillMutArryID;//选中的标签id
BOOL isbool = [skillMutArryID containsObject:((SJFourthVCModel *)(JobTagArry[i])).w_id];
if (isbool == 1) {
button.backgroundColor = main_Color;
[button setTitleColor:[UIColor lightGrayColor] forState:UIControlStateNormal];
[selectArr addObject:[NSString stringWithFormat:@"%ld",button.tag]];
NSLog(@"%@",selectArr);
}
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· Manus爆火,是硬核还是营销?
· 终于写完轮子一部分:tcp代理 了,记录一下
· 别再用vector<bool>了!Google高级工程师:这可能是STL最大的设计失误
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· 单元测试从入门到精通