Search code examples
iosxcodeinterface-buildernsattributedstringcatextlayer

CATextLayer in Interface Builder?


I would like to use a CATextLayer to display some partially bolded text in the form of a NSAttributedString - but would still like to use the convenience of IB for positioning.

Is there a way to drop in a CATextLayer with interface builder? Or what is the next best solution?


Solution

  • You could configure a UIView subclass in IB then set its layerClass to CATextLayer in code:

    + (Class)layerClass;
    {
        return [CATextLayer class];
    }
    

    In the view's init method(s) configure your CATextLayer properties.

    To access the layer's properties:

    CATextLayer *textLayer = (CATextLayer *)self.layer;
    textLayer.string = @"Foo";
    // etc...