本文介绍了CATextLayer 文本颜色始终为黑色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将 CATextLayer 添加到 UITableViewCell.问题是文本呈现为黑色,而我已经设置了它的foregroundColor.有人可以告诉我我缺少什么吗?谢谢.

I am trying to add a CATextLayer to UITableViewCell. Problem is that text is rendering as black while I have already set its foregroundColor. Can someone tell me what I am missing? Thanks.

CATextLayer *buyPrice_port = [CATextLayer layer];
buyPrice_port.frame = CGRectMake(144, 42, 76, 21);
buyPrice_port.font = (__bridge CFTypeRef)([UIFont boldSystemFontOfSize:18]);
buyPrice_port.foregroundColor = [UIColor colorWithRed:0 green:190/255.0 blue:191/255.0 alpha:1.0].CGColor;
buyPrice_port.alignmentMode = kCAAlignmentCenter;
buyPrice_port.string = @"BAC";
[self.contentView.layer addSublayer:buyPrice_port];

推荐答案

这个奇怪的问题是由于我设置字体的方式造成的.相反,它应该像这样设置:

This strange problem was due to the way I was setting my font. Instead it should be set like this:

buyPrice.font = CFBridgingRetain([UIFont boldSystemFontOfSize:18].fontName);
buyPrice.fontSize = 18;

这篇关于CATextLayer 文本颜色始终为黑色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

06-11 03:13