NSButton with round corners and background color

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

    just try to add this two lines of code into your function.I think you are getting problem in border width.

    override func drawRect(dirtyRect: NSRect)

    {
        if let bgColor = bgColor {
            self.layer?.cornerRadius = 4
            self.layer?.masksToBounds = true
            self.layer?.backgroundColor = bgColor.CGColor
            self.layer?.borderColor = UIColor.blackcolor()
            self.layer?.borderWidth = 2.0
    
            bgColor.setFill()
    
            NSRectFill(dirtyRect)
        }
    
        super.drawRect(dirtyRect)
    }
    
    0 讨论(0)
  • 2021-02-19 07:24

    If you want a button to be rounded, open up your main.storyboard, click on the button and the click on "Show the identity inspector". Under "User defined runtime attributes click on the little + sign twice. And change the code to look like this

    0 讨论(0)
提交回复
热议问题