Search code examples
iosiphonecocoa-touchuikituilabel

How to draw border around a UILabel?


Is there a way for UILabel to draw a border around itself? This is useful for me to debug the text placement and to see the placement and how big the label actually is.


Solution

  • You can set label's border via its underlying CALayer property:

    #import <QuartzCore/QuartzCore.h>
    
    myLabel.layer.borderColor = [UIColor greenColor].CGColor
    myLabel.layer.borderWidth = 3.0
    

    Swift 5:

    myLabel.layer.borderColor = UIColor.darkGray.cgColor
    myLabel.layer.borderWidth = 3.0