2中创建一个圆角矩形标签

2中创建一个圆角矩形标签

本文介绍了如何在Xcode 7和Swift 2中创建一个圆角矩形标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Xcode 7 beta 3工作。我想创建一个带圆角矩形背景的标签。默认情况下,我可以使用我选择的颜色创建背景,但我无法绕过角落。我尝试为该标签创建一个插座然后在 viewDidLoad()我写了这段代码 label.layer.cornerRadius = 10 。我没有得到任何错误,但它没有改变模拟器中的标签。有没有人知道如何在Swift 2中执行此操作?

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?

推荐答案

最简单的方法是将此属性添加到您想要的标签中有圆角。

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

layer.cornerRadius

并同时启用剪辑子视图属性。

这篇关于如何在Xcode 7和Swift 2中创建一个圆角矩形标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-02 15:58