开发者

HUD NSPanel less transparent

I've been searching for the web but I have not encountered the way to change the HUD's transparency (A开发者_如何转开发LL the panel transparency, including title bar). It's possible to change it?

Thx


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 ];


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).


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:

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜