NSButton with round corners and background color

前端 未结 8 1989
迷失自我
迷失自我 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:16

    You need to override function layoutSubviews,i.e.

    override func layoutSubviews() {
            self.layer.cornerRadius = self.frame.height/2
            self.layer.borderColor = UIColor.blue.cgColor
            self.layer.borderWidth = 2
        } 
    

    I have committed a sample project here. All your related code has been written in button.swift and it is in swift 3. Also, I have not set the background image for the button, I am leaving that task up to you.

    P.S.: The answer below is for UIButton, not NSButton. Probably some of it will be valid, probably not everything...

提交回复
热议问题