I am working in Xcode 7 beta 3. I want to create a label with a rounded rectangle background. By default, I can create a background with my color of choice but I can't round the corners. I have tried creating an outlet for that label and then in viewDidLoad()
I wrote this code label.layer.cornerRadius = 10
. I didn't get any errors but it didn't change the label in the simulator. Does anyone know how to do this in Swift 2?
You'll also want to clip to bounds of the label:
myLabel.backgroundColor = UIColor.blueColor()
myLabel.layer.cornerRadius = 10.0
myLabel.clipsToBounds = true
来源:https://stackoverflow.com/questions/31846476/how-to-create-a-rounded-rectangle-label-in-xcode-7-and-swift-2