我正在尝试向UITableViewCell添加一个CATextLayer。问题是文本呈现为黑色,而我已经设置了它的foregroundColor。谁能告诉我我错过了什么?谢谢。
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];发布于 2013-05-02 17:19:06
这个奇怪的问题是由于我设置字体的方式造成的。相反,它应该这样设置:
buyPrice.font = CFBridgingRetain([UIFont boldSystemFontOfSize:18].fontName);
buyPrice.fontSize = 18;发布于 2013-06-03 14:25:53
我只是想插一句纠正这里的信息。代码不能工作的原因是不能将UIFont转换为CGFontRef (然而,在Mac下,NSFont可以)。在Mac下,CATextLayer的字体属性可以使用字体,但在iOS下,它只能使用字体的名称作为字符串,所以您只需输入
layer.font = (__bridge CFTypeRef)@"Futura"您不应该在NSString上使用CFBridgingRetain。您将负责通过调用CFRelease来释放它。
发布于 2014-04-14 14:22:43
使用CPTMutableTextStyle来改变CPTTextLayer的字体和颜色,希望能有所帮助.
static CPTMutableTextStyle *whiteText = nil;
if ( !whiteText ) {
whiteText = [[CPTMutableTextStyle alloc] init];
whiteText.color = [CPTColor whiteColor];
}
CPTTextLayer *newLayer = [[[CPTTextLayer alloc] initWithText:titleString
style:whiteText] autorelease];https://stackoverflow.com/questions/16331345
复制相似问题