更改UITableView的textLabel和detailTextLabel的默认颜色

时间:2015-12-12 02:08:49

标签: ios swift uitableview

我希望有一种方法可以在其单元格的textLabeldetailTextLabel项目中更改UITableView文本的默认颜色。 AppDelegate中的一些代码会将其从黑色更改为其他自定义颜色。

我的应用程序的着色有点令人费解,这将是一个比明确更改它更简单的解决方案:

cell.textLabel.textColor = UIColor.blueColor()

3 个答案:

答案 0 :(得分:1)

只需创建UITableViewCell的子类,更改文本颜色,然后让应用程序中的所有其他UITableViewCell子类继承此“父”单元格。

答案 1 :(得分:0)

您可以使用UIAppearance

中的AppDelegate来完成此操作

[[UILabel appearance] setTextColor:[UIColor redColor]];

用您想要的颜色替换红色。颜色将是默认颜色,您仍然可以按标签覆盖它。

答案 2 :(得分:0)

在AppDelegate.h中添加方法

-(void)SetLabelTextColourForLabel:(UILabel*)Label;

在AppDelegate.m中添加方法实现

-(void)SetLabelTextColourForLabel:(UILabel*)Label
{
     [Label setTextColor:[UIColor redColor]];
}

并在cellForRowAtIndexPath中调用该方法

AppDelegate *app= (AppDelegate*)[[UIApplication sharedApplication] delegate];

    [app SetLabelTextColourForLabel:cell.textLabel];
    [app SetLabelTextColourForLabel:cell.detailTextLabel];

希望这能解决您的问题。

相关问题