3
votes

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.

1

1 Answers

3
votes

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.