views:

1170

answers:

1

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.

+6  A: 

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

myLabel.layer.borderColor = [UIColor greenColor].CGColor;
myLabel.layer.borderWidth = 3.0;
Vladimir
Compiler complaints that there is no definition of borderColor and borderWidth within CALayer.
Boon
they're available only starting SDK 3.0 :( If you want just a quick solution for debugging purpose you can set semitransparent colored background for your label.
Vladimir
If the compiler complains then you probably forgot to `#import <QuartzCore/QuartzCore.h>`
St3fan
@Vladmir: you saved my life. Thanks!!!!!
Digital Robot