我无法使用UITableViewCell
机制更改UIAppearance
的文字颜色。
这是我的代码,其中的评论显示了什么对我有效,哪些不对:
UITableViewCell *cell = [UITableViewCell appearance];
cell.backgroundColor = [UIColor blueColor]; // working
cell.textLabel.textColor = [UIColor whiteColor]; // NOT WORKING
cell.detailTextLabel.textColor = [UIColor redColor]; // NOT WORKING
UILabel *cellLabel = [UILabel appearanceWhenContainedIn:[UITableViewCell class], nil];
cellLabel.textColor = [UIColor whiteColor]; // working
正如您所看到的,第二种方式是工作,但我无法为普通文本和详细文本设置不同的颜色。
有什么我做错了吗?
P.S。在Interface Builder中静态定义东西对我来说不起作用 - 我的主题可以在运行时动态更改。
答案 0 :(得分:3)
您正在做正确的事情,但iOS无法使用TransformerFactory transFactory = TransformerFactory.newInstance();
Transformer transformer = transFactory.newTransformer();
StringWriter buffer = new StringWriter();
transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes");
transformer.transform(new DOMSource(document),
new StreamResult(buffer));
String result= buffer.toString();
System.out.println(result);
区分这两个标签。您应该在UIAppearance
中设置文字颜色,或者,如果您真的想使用willDisplayCell
,请创建可以更准确定位的自定义UIAppearance
子类。
如果你想使用UILabel
,它看起来像这样:
willDisplayCell
答案 1 :(得分:1)
您可以像这样设置文字颜色。
[cell.textLabel setTextColor:[UIColor whiteColor]];
[cell.detailTextLabel setTextColor:[UIColor redColor]];