我是iOS上的新手,很抱歉我的英语不好。
我想通过改变外观主题到我的应用程序
UIAppearance
代理。然后我有一些不同的单元格,它们是UITableViewCell
的子类,每个单元格都有一个样式。
某些单元格中的某些标签具有不同的颜色,因此单元格的“textLabel
”属性可能在单元格中为白色,在另一个单元格中为红色。
我有一个UILabel
子类,例如,用于文本的红色。
我更改了此标签的外观颜色如下:
[[MyRedLabel appearance] setTextColor:[UIColor redColor]];
我想使用相同的单元格,所以我做的是覆盖这样的方法:
-(UILabel*) textLabel {
//(MyRedLabel is only put for test purposes, lastly I'll remove it by a property that will be what I want)
return [[MyRedLabel alloc] initWithFrame:CGRectMake(0, 0, 0, 0)];
}
问题是当TableView绘制单元格时,文本不是。你能帮帮我吗? 感谢。
[编辑]
对不起,如果我没有解释。我有一个UILabel的子类用于我想要的每种颜色,所以如果我想要蓝色标签,我会这样做:
[[MyBlueLabel appearance] setTextLabel:[UIColor blueColor]];
我想要将我想要的标签分配给一个单元格:
//Cell1
MyCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Identifier"];
if (cell == nil) {
cell = [[[MyCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier] autorelease];
}
cell.textLabel = [[MyBlueLabel alloc] initWithFrame:CGRectMake(0, 0, 0, 0)];
//...
//Cell2
//....
cell.textLabel = [[MyRedLabel alloc] initWithFrame:CGRectMake(0, 0, 0, 0)];
然后当我做 cell.textLabel.text = @“Hi world”; 文本在cell1中为蓝色,在cell2中为红色。
我想知道这是否正确,因为我不想用他的.xib创建4个或更多自定义单元格
答案 0 :(得分:0)
不清楚你在问什么。但是你不应该使用[MyReadLabel外观]来设置属性,除非你想要所有UILabel以相同的方式运行。在你的情况下,就像你说的那样,我认为你误用了这些方法。