PDA

View Full Version : Make Window background semi transparent




SRossi
Jun 22, 2009, 12:01 PM
Hi all again, I'm trying to change the transparency of the background of a Window. This will be done on a click of a button which is placed on the window.

Heres my code so far:

- (IBAction)changeOpacity:(id)sender
{
NSWindow *aWindow;

[aWindow setOpaque:NO];
NSColor *semiTransparentBlue = [NSColor colorWithDeviceRed:0.0 green:0.0 blue:1.0 alpha:0.5];
[aWindow setBackgroundColor:semiTransparentBlue];
}

PS I dont know how to set the current window to aWindow help with that would be good as well :)

Thanks all in advance

Stephen



SRossi
Jun 22, 2009, 01:27 PM
Got it working my mistake, but can i ask how would I make the background change when the user moves a slider ?

Can I bind the value of the slider to the background of the window?

Stephen

kainjow
Jun 22, 2009, 03:12 PM
You can observe for changes to that value in your controller, and then set the background color. See addObserver:forKeyPath:options:context:

SRossi
Jun 22, 2009, 07:02 PM
Right I created a binding in IB from a slider to a float i created but when i move the slider it creates all kind of funny numbers.

Should I create the binding programatically as kainjow says, if so is there any sample code that I could use?

Thanks.

Stephen