如何在 Swift 中使按钮具有圆角边框? [英] How can I make a button have a rounded border in Swift?

查看:27
本文介绍了如何在 Swift 中使按钮具有圆角边框?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在最新版本的 Xcode 6 中使用 swift 构建一个应用程序,我想知道如何修改我的按钮,以便它可以有一个圆形边框,我可以在需要时自行调整.完成后,如何在不添加背景的情况下更改边框本身的颜色?换句话说,我想要一个没有背景的稍微圆润的按钮,只有某种颜色的 1pt 边框.

I'm building an app using swift in the latest version of Xcode 6, and would like to know how I can modify my button so that it can have a rounded border that I could adjust myself if needed. Once that's done, how can I change the color of the border itself without adding a background to it? In other words I want a slightly rounded button with no background, only a 1pt border of a certain color.

推荐答案

使用 button.layer.cornerRadiusbutton.layer.borderColorbutton.layer.borderWidth.请注意,borderColor 需要一个 CGColor,因此您可以说 (Swift 3/4):

Use button.layer.cornerRadius, button.layer.borderColor and button.layer.borderWidth. Note that borderColor requires a CGColor, so you could say (Swift 3/4):

button.backgroundColor = .clear
button.layer.cornerRadius = 5
button.layer.borderWidth = 1
button.layer.borderColor = UIColor.black.cgColor

这篇关于如何在 Swift 中使按钮具有圆角边框?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆