Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Translucent NSView

I have an NSView in an NSWindow, the NSWindow is the standard Mac grey/beige colour.

I want to make the NSView slightly translucent and grey (e.g. grey color with alpha of 0.2), so that the background (beige) of the NSWindow shows through.

If I draw a rect in the NSView in drawRect, the alpha value is ignored and is always one.

On the iPhone when this happens I set the UIView's opaque property to NO, however NSView has o such property.

I set the opaque property on the NSWindow to NO, and it made the NSView accept transparency but made the NSWindow below the NSView completely transparent and I could see the desktop beneath.

like image 789
Jonathan. Avatar asked Nov 30 '25 17:11

Jonathan.


1 Answers

On the iPhone when this happens I set the UIView's opaque property to NO, however NSView has o such property.

It does, but it's read-only, so you can only change it by overriding in a subclass. Moreover, it's NO by default, so you don't need or want to do that.

Did you make the view layer-backed? setAlphaValue: doesn't work on views that don't have layers; in fact, the documentation says that a view without a layer will throw an exception if you try to set its alpha value.

like image 144
Peter Hosey Avatar answered Dec 03 '25 11:12

Peter Hosey



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!