【发布时间】:2017-02-01 03:34:45
【问题描述】:
我有一个 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:>
【问题讨论】:
-
你怎么知道背景颜色没有改变?您发布的代码看起来不错。
-
@rmaddy 我
[self addSubview:tag];将它添加到我的视图中。 -
您可能需要发布更多代码,因为您的代码看起来完全正确。
标签: ios objective-c uilabel uibackgroundcolor