0
votes

So I have an NSView in which I created some borderless buttons programmatically.

Although I set their backgroundColor property to desired color, they show up like they have a darker shade.

How could this be happening?

3
Are you positive that is not the color you expect? Try using Digital Color Meter.app (built-into macOS), to check the color to see if it's not the RGB values you inputted. The colorspace is also relevant, it could be that it is different from what you are expecting - A O
Thank's for your comment! Considering what you say, it may be something more I have to deal with, regarding the backgroundColor property of the NSButton instance. I also use a NSLabel entitled 'Choose a device' for which I also set the background color to be the same as the view's. I have no problem there. - J. Dove
Try setting the backgroundColor for the button to white, what do you see? - A O
+1 for @Hashmat. You provided nearly no close (much less IB definition) of anything. Maybe you set the color in IB to something not available by default in UIColor. Maybe you set the alpha value to something in code that is giving you the visual output you are seeing. Can you provide more detail? - dfd
As others said before, try using NSColor.clearColor (also selectable in Interface Builder) for the button. Also, make sure that the button's appearance is Aqua, not vibrant. - MrMage

3 Answers

6
votes

I guest that is the background of Label not of Button, which does not appear when users choose to reduce transparency in System Preferences.

In that case, I have solved by this line of code:

myButton.appearance = NSAppearance(named: .aqua) 
0
votes

here How I would do it as I mentioned in comment. The custom view is connected as iboutlet and given green color. Label has by default no back ground color. The button has no border and of type Round Rect as you see in screen shot. The blue color around button is the selection/ active control, but you can get rid of that too.

self.testBtn.focusRingType = NSFocusRingTypeNone;

enter image description here

edit add new image showing scroll bar: enter image description here

0
votes

//set background color

button.backgroundColor=[UIColor clearColor]

//then set tint color of button

[btn setTintColor:[UIColor clearColor]];