最新消息:20210816 当前crifan.com域名已被污染,为防止失联,请关注(页面右下角的)公众号

[已解决]swift实现圆角的按钮

Swift crifan 3735浏览 0评论

swift中,想要给按钮,变成圆角的。

用了:

var loginButton:UIButton = UIButton(type: UIButtonType.RoundedRect)

但是没效果,试试默认的直角的:

swift default is rectangle corner button

 

搜:

swift round circle button
参考:
看到官网:
中说了:RoundedRect在iOS 7之后就废弃了
-》难怪代码没用
最后去用:
        loginButton.layer.cornerRadius = 16
或:
        loginButton.layer.cornerRadius = 16
        loginButton.layer.borderWidth = 2
       loginButton.layer.borderColor = UIColor(hexString: "#249ed8")?.CGColor
效果:
show round corner button
[总结]
iOS中,用swift设置圆角的button的话:
iOS 7之前,用:
var loginButton:UIButton = UIButton(type: UIButtonType.RoundedRect)
iOS  7之后用:
var loginButton = UIButton()
loginButton.layer.cornerRadius = 16
如果需要,再去设置,边框的宽度和颜色:
loginButton.layer.borderWidth = 2
loginButton.layer.borderColor = UIColor.redColor().CGColor

转载请注明:在路上 » [已解决]swift实现圆角的按钮

发表我的评论
取消评论

表情

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址
86 queries in 0.165 seconds, using 22.07MB memory