1

I've been searching for the web but I have not encountered the way to change the HUD's transparency (ALL the panel transparency, including title bar). It's possible to change it?

Thx

Andreu
  • 11
  • 2

3 Answers3

3

You should be able to use the setAlphaValue, inherited from NSWindow:

http://developer.apple.com/library/mac/#documentation/Cocoa/Reference/ApplicationKit/Classes/NSWindow_Class/Reference/Reference.html

[ myPanel setAlphaValue: 0.5 ];
Macmade
  • 52,708
  • 13
  • 106
  • 123
  • Thx but the problem is that [self setAlphaValue: 1] is default HUD transparency. I wanna less transparency! – Andreu Mar 26 '11 at 17:46
  • I wanna less transparency than AlphaValue=1 so "AlphaValue should be > 1" – Andreu Mar 26 '11 at 19:38
  • Ok... So you need something else that a HUD window, that is transparent by default, with an alpha of 1... – Macmade Mar 26 '11 at 20:33
  • @Andreu: alpha goes from 1.0 to 0.0, with 1.0 being fully opaque and 0.0 being fully transparent. 0.5 is _more_ transparent than 1.0. – jscs Mar 27 '11 at 04:22
1

It is possible. You just need to do it programmatically by setting the color (including alpha) on the Core Animation layer of the panel's view. Here is an example of setting the HUD panel with slightly less transparency:

view.layer.backgroundColor = [NSColor colorWithSRGBRed:0.2 green: 0.2 blue: 0.2 alpha:0.7].CGColor

Just remember that you have to do this after the view has loaded, eg. don't set it in init:

1

It's not possible. HUD panels are intended to be transparent; they won't let you change their opacity or the opacity of their base views.

NSLog(@"opaque before? %@", [hud isOpaque] ? @"YES" : @"NO");
[hud setOpaque:YES];
NSLog(@"opaque after? %@", [hud isOpaque] ? @"YES" : @"NO");

OpaqueHUD[18952:a0b] opaque before? NO
OpaqueHUD[18952:a0b] opaque after? NO

NSLog(@"alpha before: %.2f", [hud alphaValue]);
[hud setAlphaValue:1.0f];
NSLog(@"alpha after: %.2f", [hud alphaValue]);

OpaqueHUD[18952:a0b] alpha before: 1.00
OpaqueHUD[18952:a0b] alpha after: 1.00

NSView * contentView = [hud contentView];    
// In layer-backed mode
NSLog(@"content alpha before: %.2f", [contentView alphaValue]);
[contentView setAlphaValue:1.0];
NSLog(@"content alpha after: %.2f", [contentView alphaValue]);

OpaqueHUD[18952:a0b] content alpha before: 1.00
OpaqueHUD[18952:a0b] content alpha after: 1.00

You'll have to: 1) put a custom opaque subview in there and live with a translucent title bar; b) use an NSPanel with the regular style, whose background color and opacity you can change, and live with it being a regular title bar; or d) create your very own custom window (good link to another writeup at the bottom of that article). See also this article about making your own window frame (warning: that one uses private API, and is a few years old).

jscs
  • 63,694
  • 13
  • 151
  • 195