NSButton with round corners and background color

前端 未结 8 1990
迷失自我
迷失自我 2021-02-19 06:30

I want a simple push button (the one with the round corners), and to add background to it. I\'ve tried 2 things:

1 - using a round button image: this is working good, un

8条回答
  •  终归单人心
    2021-02-19 07:11

    Simple 3 line function.

    @IBOutlet weak var button: UIButton!
    
    func setButton(color: UIColor, title: String)  {
        button.backgroundColor = color
        button.setTitle(title, forState: .Normal)
        button.layer.cornerRadius = 8.0
    }
    

    and call it like such

     setButton(UIColor.redColor(), title: "Hello")
    

提交回复
热议问题