Toggle NSToolbarItem between Black and Blue - macos

I'd like to make an NSToolbarItem with a custom image which toggles between Black and Blue, like the icons at the top right of Xcode 5's main window.
Peter Hosey suggested in this answer that it was as simple as setting the image to be a template, but I haven't found that to be the case. I set it to a template image, and that causes it properly render the dark gray gradient, but it doesn't render in blue when toggled.
I uploaded a very simple example of what I've done, here. If someone could tell me how to change it to light up the NSToolbarItem in blue, as Xcode does, then I'd very much appreciate it.

You mostly have everything you need in place, with the exception of providing an NSButton object using the style NSTexturedRoundedBezelStyle, with which you’ve associated your image.
↳ modified example project here
⌘ OS X Human Interface Guidelines | Window-Frame Controls

Related

Custom Button in Swift and MacOS

In MacOS there is a simple App called Calculator, that I would like to recreate using Swift for learning purposes. A button like the plus button on the calculator has two images associated with it, one when the button is up and one when the button is down, as seen on the images below.
As you can see, when the + button is pressed down, its image changes to a darker orange color and the text gets a dark grey color. My question is: How to implement this button behavior?
Is it possible to do it with NSButton (and if so how)? or is it easier to implement it using CALayer? Or maybe there is some other way that I have not thought of?
You should be able to use a single image and configure it in code or in your asset catalogue to be a "template image". That means the shape is taken into consideration, much like a stamp, and the stamped-out area is filled with color dynamically. That means you don't have to provide a white and dark gray/black variant. One variant will suffice, usually black to see the lines well, and the rest can be configured through.
See the SO question "How to NOT highlight the NSButton's template image when clicked?" for details about the setup: How to NOT highlight the NSButton's template image when clicked?

Change Background Color of Full Screen Application- Xcode

Good Afternoon helpful people!
I'm building a mac app that displays images. The app will be in fullscreen mode 100% of the time it is running.
My issue is that the images I am displaying do not fill the entire screen, therefore, showing a grayish background. Is there anyway to change this background color to Black? Or maybe it's the NSImageView that needs the background color changed?
I do not see anywhere in my Xcode Attributes Inspector to change color.
Thanks!
The solution to this is, in my case, to add an NSBox in storyboard and set its constraints so that it ALWAYS fills the view. Once you have done this, go to the Atrributes Inspector and change its Fill Color to your desired color.
The important part here is the constraints. Set Top, Bottom, Left, and Right space to 0. Hope that makes sense, i'm new to constraints.

Wrong color in Interface Builder's color picker

I have an UIImageView with a brown image that will not always reach the top part. The UIImage view is inside a white UIView.
So, because the top part of the image is a linear brown color, I said I will make the UIView underneath it the same brown color, and the user will not see where the image ends. So far, so good.
My problem is, when I pick the color in the top part of the image, the color picker picks a more darker color than actually is there :(
Before I click the color picker:
After I click the color picker:
How comes ?
Just wanted to elaborate upon the accepted answer with some screenshots.
If you want to match RGB values between Photoshop and Xcode exactly (without conversion between colorspaces) then you need to save your images in generic RGB and enter any dropper values using the generic RGB colorspace.
When you choose "Save for Web & Devices" from Photoshop, uncheck the "Convert to sRGB" box.
In Xcode, click the colorspace popup in the color picker and choose "Generic RGB", then enter the red, green and blue values from Photoshop, NOT THE HEX VALUE as this reverts back to the sRGB colorspace for some reason (be careful not to tab to the hex field either, as that also changes the colorspace to sRGB).
More info here, including how to match screenshots.
I've managed to find out a solution/explanation (tho I'm still confused) in this answer: https://stackoverflow.com/a/9203647/460750
Basically, what I did to solve my issues, was to choose from the RGB "types" select (that little square under the color picker) the Apple RGB option, and enter the R, G and B values manually, instead of using the picker.
Odd...
Its because the component numbers don’t spec a color. We also need to know the color space which xCode uses. Colorspace which encodes or decodes is available in the drop down left to the RGB slider.
By default xCode chooses the "Generic RGB" and that is what UIColor uses spec color from RGB. If we use magnifying glass, it will change to "Device RGB” space and that is based on your current screen.
So “sRGB" or "Adobe RGB" would be the better or close to what you want if you are using the magnifying glass to pick a color.
I think Generic RGB also works.
the trick is you need to enter number of R G B manually
after change the RGB mode in dropdown list
Odd... (too)
UPDATE 10.10.4
I had this issue as well, I reported it to Apple, and it seems to have been solved on 10.10.4 (it was related to the color picker itself, not to Xcode/IB)
Can someone else confirm it?
This is an old question, but it was important for me to add some info.
The only method that has been working for me accurately over the years was to not use PS's Color Picker, but use macOS' built-in "Digital Color Meter".
It's bundled with every installation of macOS and the RGB values emitted from there with "Generic RGB" always reproduce the correct color in Xcode Storyboards.

Transparent rounded window but with opaque controls

I am trying to make a HUD with a transparent rounded window with opaque controls as is commonly seen in apps such as Xcode popups, the native volume control, etc.
I'm using the technique detailed here: How to implement HUD-style window like Address Book's "Show in Large Type"
but this renders controls in the view transparent. I've tried setAlphaValue:1.0 on the controls but that has no effect. Searches for other solutions point to Matt Gemmell's RoundedFloatingPanel component. I can't open the project in Xcode 4, but looking at the code as far as I can tell the only difference seems to be in Matt's code he sets the alpha of the window to 1.0 and uses a transparent fill for the NSRect in the view. I tried this but still end up with transparent controls.
So unsurprisingly, Matt Gemmell's code works just fine and I had made a mistake. I forgot that I was also messing with the alpha of the window elsewhere in my code in order to make it fade out on close.
To to sum it up for others running into this issue, if you set the alpha on the NSWindow the controls in that window will also be transparent. Instead set the alpha on the NSBezierPath fill color in the NSView. Just like Matt Gemmell's code does. :)

Make NSToolbar Icon for NSToolbar

I'd like to make an icon for my NSToolbar that has the same system stylings applied to it as the template icons in IB. How do you do this? I can't get the toolbar to apply system stylings like it says it will in the HIG.
Thanks!
In Mac OS X v10.5 or later, images whose name ends in the word "Template" are automatically marked as template images. NSImage Class Reference
NSImage *image = [NSImage imageNamed:#"MyImageTemplate"];
This also works for Interface Builder.
More information: http://www.proppe.org/blog/2007/12/01/nsimage-templates/
If you mean for a monochromatic icon, make sure you set it as a template image. That's what tells the system to render it with the inner gray or blue gradient.
The toolbar doesn't do that automatically. You have to create the graphics yourself. The Lion-style icons are usually mid-gray with a subtle inner shadow and a 1px whitish drop shadow. Here's an example done in Photoshop:
And here's all the layer styling done to it:
The specific numbers and colors may vary depending on the icon's shape and size.
On a side note, the HIG was saying that icons may change depending on the control. For example, when you disable a button, its icon will be displayed semi-transparently.

Resources