Is it possible to add a UILabel
to a CALayer
without subclassing and drawing it in drawInContext:
?
Thanks!
Your UILabel already has a CALayer behind it. If you are putting together several CALayers, you can just add the UILabel's layer as a sublayer of one of those (by using its layer property). If it's direct text drawing in a layer that you want, the UIKit NSString additions that Deepak points to are the way to go.
Overview. Layers are often used to provide the backing store for views but can also be used without a view to display content. A layer's main job is to manage the visual content that you provide but the layer itself has visual attributes that can be set, such as a background color, border, and shadow.
CATextLayer *label = [[CATextLayer alloc] init]; [label setFont:@"Helvetica-Bold"]; [label setFontSize:20]; [label setFrame:validFrame]; [label setString:@"Hello"]; [label setAlignmentMode:kCAAlignmentCenter]; [label setForegroundColor:[[UIColor whiteColor] CGColor]]; [layer addSublayer:label]; [label release];
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With