How to round edges of UILabel with Swift
Use label layer corner radius to do that,
mylabel.layer.cornerRadius = yourvalue
if you don't want to show shadow then add,
mylabel.layer.masksToBounds = true
it worked for me fine.
You can give cornerRadius
and border like this.
For Swift 5, 4 and 3
MyLable.layer.masksToBounds = true
MyLable.layer.cornerRadius = 6
MyLable.layer.borderWidth = 2
MyLable.layer.borderColor = UIColor.black.cgColor
For Objective-C
[MyLable.layer setMasksToBounds:TRUE];
[MyLable.layer setCornerRadius:6];
[MyLable.layer setBorderWidth:2];
[MyLable.layer setBorderColor:[UIColor blackColor].CGColor];
The trick is to set maskToBounds
to true. Then your modifications to cornerRadius
will be visible.
label.layer.masksToBounds = true
label.layer.cornerRadius = 5
Assuming you have added a backgroundColor
to your label otherwise there would be no way to tell if it had edges, you can use QuartzCore to round the edges of a label.
import QuartzCore
yourLabel.layer.backgroundColor = UIColor.redColor().CGColor
yourLabel.layer.cornerRadius = 5
yourLabel.layer.masksToBounds = true