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

后端 未结 15 2105
庸人自扰
庸人自扰 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条回答
  • 2021-01-29 18:16

    I think this is the simple form

    Button1.layer.cornerRadius = 10(Half of the length and width)
    Button1.layer.borderWidth = 2
    
    0 讨论(0)
  • 2021-01-29 18:17

    as aside tip make sure your button is not subclass of any custom class in story board , in such a case your code best place should be in custom class it self cause code works only out of the custom class if your button is subclass of the default UIButton class and outlet of it , hope this may help anyone wonders why corner radios doesn't apply on my button from code .

    0 讨论(0)
  • 2021-01-29 18:25

    TRY THIS Button Border With Rounded Corners

    anyButton.backgroundColor = .clear
    
    anyButton.layer.cornerRadius = anyButton.frame.height / 2
    
    anyButton.layer.borderWidth = 1
    
    anyButton.layer.borderColor = UIColor.black.cgColor
    
    0 讨论(0)
提交回复
热议问题