CATextLayer textcolor is always black

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;

Just thought I would chime in to correct the information that is here. The reason for your code not working is that UIFont cannot be casted to CGFontRef (NSFont can however under Mac OS X). CATextLayer's font property can expect a font under Mac OS but under iOS it can only use the name of the font as a string, so you could just type

layer.font = (__bridge CFTypeRef)@"Futura"

You should not be using CFBridgingRetain on the NSString. You would be responsible for releasing it by calling CFRelease.

Need Your Help

C++ Expected class-name before '{' token. Inheritance

c++ inheritance

I've been googling and reading about this and didn't come up with an answer yet, maybe someone can help me with this.

UINavigationController setViewController:animated: navigation bar difficulties

iphone uiviewcontroller uinavigationcontroller

I'm having an incredibly frustrating problem that appears to be a bug, but I have a very hard time believing no one else has come across this. My application's root view controller is a

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.