I'm having no luck trying to get NSPopover back to its 10.9 appearance when running in 10.10. I have a popover which is attached to an NSView that the user drags around. The popover must be transparent so the user can still see the position of the other UI elements underneath.
All works fine under 10.9 but now under 10.10 with Apple's new gimmicky blurs, I can't seem to get back to the same appearance on 10.10 (unless like me, the user has enabled "Reduce Transparency" in System Preferences > Accessibility. A preference change I can't enforce on end users!).
Have tried:
self.draggingPopover.appearance = NSPopoverAppearanceHUD;
self.popoverView.superview.appearance = [NSAppearance appearanceNamed:NSAppearanceNameAqua];
self.popoverView.appearance = [NSAppearance appearanceNamed:NSAppearanceNameAqua];
None of which make any difference to the popover's appearance on screen.
drawRect in my view subclass fills the background with my chosen color but ignores the alpha value and the popover is opaque.
Similarly I can use self.popoverView.layer.backgroundColor = ... but the alpha value is ignored there too!
Use:
[popover setAppearance:(NSPopoverAppearance)[NSAppearance appearanceNamed:NSAppearanceNameAqua]];
If a requirement is that the popover is transparent (regardless of any future design changes to popover), could you just set the popover window's (i.e. the popoverView's -window) alphaValue to some other value < 1.0?
You can set the Aqua appearance in the storyboard as well. Select the NSPopover's content view and use this setting:
Related
There are some NSColor initialization helpers like controlColor() which return various colors of system components. Is there any such thing for the dock and menubar? I couldn't see one by name that popped out. If there is no such helper, is there another way to get the color?
I want to use it as the default NSWindow background color for a utility application I am developing that will be displayed in a small, borderless NSWindow.
They are both controlled from the 'General' panel in 'System Preferences' shown in the figure below.
Thanks in Advance.
No, the menu bar and Dock background appearances aren't NSColor system colors. They do look a lot like the Dark Vibrant and Light Vibrant styles you can get from NSVisualEffectView, though.
If you want to change your view's appearance to match the state of the "Use dark menu bar and Dock" preference... well, there's no API for that, but you can read that preference from where it's stored. (Since it's not API, caveat emptor: there's no guarantee the preference storage won't change in later OS X versions.)
In Swift (and broken into several lines for clarity):
let defaults = NSUserDefaults.standardUserDefaults()
let globalPrefs = defaults.persistentDomainForName(NSGlobalDomain)!
let interfaceStyle = globalPrefs["AppleInterfaceStyle"]
if interfaceStyle as! String == "Dark" {
// time to be all emo
}
I have an app which has a NSStatusItem that uses a custom view. I apply an alpha value to the status item's view when a process in the app in inactive. This works fine, except on OS X 10.9 - 10.10 when multiple displays (monitors) are present. The system menu bar auto-applies an alpha value to itself when it is on an inactive display. On the inactive display, the custom view in my status item seems to completely disappear.
I am guessing that OS X auto-applying an alpha value to the menu bar on the inactive display is combining with the alpha value I am setting directly to the view and causing the view to have an overall alpha value of 0 or less.
Any ideas on how to handle this? Thanks in advance!
As far as I know, to display an inactive NSStatusItem you should use another image, that is the same as the one used when active, but with a grey color (and that image must have template = true).
I guess that applying an alphaValue to the item works just because that is the way that the system uses when a second monitor is attached.
I want to have a unified toolbar and therefore I found this post:
How can I create Yosemite-style unified toolbar in Interface Builder?
self.window.titleVisibility = NSWindowTitleVisibility.Hidden
works perfect.
But is there a way to change the background color for the toolbar? I tried with self.window.appearance = NSAppearance(named: NSAppearanceNameVibrantDark), but this only brings a complete black toolbar (that's too dark). I want to have a custom color.
This one works:
https://stackoverflow.com/a/28692893/2062613
Set the window to textured in IB (I don't see a possibility to do it at runtime)
Use this code:
self.window.titleVisibility = NSWindowTitleVisibility.Hidden
self.window.backgroundColor = NSColor.whiteColor()
UPDATE:
To prevent, that the toolbar becomes transparent in Yosemite (if you have a scrollview below the Toolbar), use this code:
self.window.appearance = NSAppearance(named: NSAppearanceNameAqua)
I have used this solution to customize the title bar. However, since 10.15.4 and apparently on Big Sur, the toolbar is broken. If you have a toolbar with the window, the toolbar will placed on the top edge of the window, as if there is no title bar.
I'm new to Xcode (Mac development, not iOS), and for some reason I can't figure out how to even change any object's color (text, background or really anything). Every site seems to say to click on the object, go to the attributes inspector and all of those options are under 'view'. However, in my Xcode (5.1.1) all it shows under 'view' is tag, focus ring, drawing, and auto-resizing. Am I missing something obvious?
On OS X, NSView does not have an intrinsic backgroundColor property. Thus, you cannot set the color of a view from Interface Builder. You have to create an NSView subclass and override -drawRect: or -updateLayer to make it the color you want. Even then, that color will not show up in Interface Builder. (This changes in Xcode 6, which is still in beta as of this writing.)
Is this somewhat annoying? Yeah. But that's the way it is.
As for changing the text of an object, you should be able to do it from the Attributes inspector, but only if it's something that already has text (i.e. a text field, text view, or button). An arbitrary custom view does not have text, so you can't set it in Interface Builder.
You should easily be able to set the background color of whatever UI element you want programmatically.
[viewObject setBackgroundColor:[UIColor greenColor]];
As for editing a xib for OSX I'm not sure. I have only done iOS development.
This must have been asked before, but after Googling I still can't find the answer.
How do you change the color of the title bar (The bar that you can click and drag around with the close, minimize and maximize buttons) to a different color than the default gray in Cocoa?
If you set the background color of a "textured" window (a distinction that isn't really all that visible in Snow Leopard) that color will be applied to the titlebar as well. This is what Firefox does.
I would recommend though not having a real titlebar (i.e. setting your window to have no titlebar) and using +[NSWindow standardWindowButton:forStyleMask:] and putting your own buttons in the "titlebar". This allows you more control and is way way less hacky.
If it's a panel, you can change it to black by instantiating it as a HUD window.
Otherwise, you can't. Ever notice how there aren't any Aqua windows with different-colored title bars roaming around in other apps? This is why.
The only other way to change the appearance of the title bar (without relying on private implementation details such as the existence of a frame view) is to make the window borderless and create its title bar and window buttons from the ground up.
If you go with Colin's approach of making the window textured in interface builder (check box in the attributes of the window), here's the line to change the background color of the window you'd put in this function of the appDelegate.m file
//In this function --->
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
//type this
[_window setBackgroundColor: NSColor.whiteColor];
If you don't mind private API, you could subclass NSThemeFrame.
Setting title bar appears as transparent
self.window.titlebarAppearsTransparent = YES;
And setting window background color as you wish