How to create a rounded rectangle label in Xcode 7 and Swift 2

你。 提交于 2019-12-04 05:35:30

The most simplest approach is to add this attribute to the label you want to have rounded corners.

layer.cornerRadius

And also enable Clip Subviews property as well.

You'll also want to clip to bounds of the label:

myLabel.backgroundColor = UIColor.blueColor()
myLabel.layer.cornerRadius = 10.0
myLabel.clipsToBounds = true

A view can optionally limit the drawing of its subviews so that any parts of them outside the view are not shown. This is called clipping and is set with the view’s clipsToBounds property.

So you need to add:

label.clipsToBounds = true 

result (Swift 2.0 Xcode 7 iOS9):

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!