我有一个数组UILabels
。
UILabel *tag = [[UILabel alloc]initWithFrame:CGRectMake(offx,offy, 200, 50)];
[tag setTextColor:[UIColor whiteColor]];
[tag setFont:tagText.font];
tag.numberOfLines = 0;
[tag setText:tagText.text];
[self addSubview:tag];
[_tagArray addObject:tag];
然后稍后我想更改此数组中一个标签的背景颜色。
NSLog(@"%@", [_tagArray lastObject]);
UILabel *l = (UILabel *)[_tagArray lastObject];
[l setBackgroundColor:[UIColor redColor]];
[[_tagArray lastObject] setBackgroundColor:[UIColor redColor]];
在日志中,我得到了我创建的标签,但背景颜色没有改变。
UILabel: 0x15fec10c0; 帧 = (6 78; 52 29); 文字='嗨'; clipsToBounds = YES; 用户交互启用 = 否;层 = <_UILabelLayer: 0x174298240