Make Window background semi transparent

Discussion in 'Mac Programming' started by SRossi, Jun 22, 2009.

  1. macrumors regular

    Joined:
    May 27, 2009
    Location:
    Glasgow, Scotland
    #1
    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:

    Code:
    - (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
     
  2. thread starter macrumors regular

    Joined:
    May 27, 2009
    Location:
    Glasgow, Scotland
    #2
    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
     
  3. Moderator emeritus

    kainjow

    Joined:
    Jun 15, 2000
    #3
    You can observe for changes to that value in your controller, and then set the background color. See addObserver:forKeyPath:eek:ptions:context:
     
  4. thread starter macrumors regular

    Joined:
    May 27, 2009
    Location:
    Glasgow, Scotland
    #4
    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
     

Share This Page