How to make a simple rounded button in Storyboard?

后端 未结 13 1829
渐次进展
渐次进展 2021-01-29 19:49

I just started learning iOS development, cannot find how to make simple rounded button. I find resources for old versions. Do I need to set a custom background for a button? In

13条回答
  •  傲寒
    傲寒 (楼主)
    2021-01-29 20:16

    1. Create a Cocoa Touch class.

    enter image description here

    1. Insert the code in RoundButton class.

      import UIKit
      
      @IBDesignable
      class RoundButton: UIButton {
      
          @IBInspectable var cornerRadius: CGFloat = 0{
              didSet{
              self.layer.cornerRadius = cornerRadius
              }
          }
      
          @IBInspectable var borderWidth: CGFloat = 0{
              didSet{
                  self.layer.borderWidth = borderWidth
              }
          }
      
          @IBInspectable var borderColor: UIColor = UIColor.clear{
              didSet{
                  self.layer.borderColor = borderColor.cgColor
              }
          }
      }
      
    2. Refer the image.

    enter image description here

提交回复
热议问题