Iphone CATextLayer doesn't show it's text.

Posted by lovecactus on Stack Overflow See other posts from Stack Overflow or by lovecactus
Published on 2010-06-18T08:59:02Z Indexed on 2010/06/18 9:03 UTC
Read the original article Hit count: 383

Filed under:
|

Here is my new bee issue: I was simply trying to add a CATextlayer in an UIView layer. However, according to the following code, I only get the CATextlayer's background color be displayed in the UIView, without any text. Just wonder what did I missed to display the text.

Could anyone ofter a hint/sample how to use CATextlayer? Thanks.

  • (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil { if ((self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil])) { // Custom initialization

    CATextLayer *TextLayer = [CATextLayer layer];
    TextLayer.bounds = CGRectMake(0.0f, 0.0f, 100.0f, 100.0f);
    TextLayer.string = @"Test";
    TextLayer.font = [UIFont boldSystemFontOfSize:18].fontName;
    TextLayer.backgroundColor = [UIColor whiteColor].CGColor;
    TextLayer.wrapped = NO;
    
    
    //TextLayer.backgroundColor = [UIColor blueColor];
    self.view = [[UIView alloc] initWithFrame:CGRectMake(0.0f, 0.0f, 100.0f, 100.0f)];
    self.view.backgroundColor = [UIColor blueColor];
    [self.view.layer addSublayer:TextLayer];
    [self.view.layer layoutSublayers];
    

    } return self; }

© Stack Overflow or respective owner

Related posts about iphone

Related posts about ui