How can I make a button have a rounded border in Swift?

后端 未结 15 2106
庸人自扰
庸人自扰 2021-01-29 17:50

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 mys

15条回答
  •  闹比i
    闹比i (楼主)
    2021-01-29 18:14

    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
    

提交回复
热议问题