Set global tint in Cocoa applications - cocoa

I noticed that many apps uses a custom global tint color like Pages (Yellow) or Music (Red). NSAlert default buttons respect this tint, as NSOpenPanel and others do (for example drop-down arrow as show in picture).
I alos noticed that NSAlert brings a delete button that shows text in red. Do you know how to get it to appear?
Thanks
How could I specify a specific global color. I create UI using code and not Storyboard.

Searching in Apple's app folders, such as Pages, I found what we need to do to change the app's overall tint.
Create a color object in the Asset;
In the info.plist add the key NSAccentColorName that is a string assigned to the color name created at step 1;
This colors NSAlert default buttons and all control's accent elements.

Related

Use combined titlebar + toolbar while preserving title visibility

The System Preferences app feature a combined title bar and toolbar with vertically centered buttons and the title. I am trying to mimic this exactly in my app. I have been able to combine the title bar and toolbar using Interface Builder (on the NSWindow check Title Bar and Unified Title and Toolbar), but this does not center the content vertically. I discovered via this question you can simply set the window's titleVisibility to NSWindowTitleHidden which will vertically center the stoplight buttons. Unfortunately this of course hides the title. How can one vertically center content in the unified titlebar/toolbar and also show the window's title just like System Preferences - either in IB or programmatically?
I ended up setting titleVisibility to NSWindowTitleHidden and manually created an NSView that contains an NSTextField that mimics the standard title appearance, providing that to the window's addTitlebarAccessoryViewController method. Still would like to find a better solution to use the default title appearance, if possible.
I used WAYAppStoreWindow on GitHub to do this. I created a fork of the WAYWindow subproject to vertically centre the document title since this wasn't supported. This means any applied themes/appearances are honoured.

How to change Label Font with the FontsPanel in cocoa

I made a PushButton to open up a Font Panel like they did here:Make NSButton open fonts panel
I did all of these through the Interface-Builder by dragging buttons and Labels onto the MainMenu View and i have nothing inside my AppDelegate.h and .m
Im really new to objective c and cocoa so i was wondering if anyone could give me an in depth explanation on how to use that font panel to edit the font in a Label or a Text Field.
Both label and text field are class NSTextField.
The style of the text they display is determined by the attributes on their NSAttributedString.
The Attributed String Programming Guide on Apple's developer site goes into detail on how to handle attributes. The font is one of those inside an attribute called paragraph style.
That should get you started on what to look into.
The Cocoa text architecture is pretty rich and can take some time to get familiar with.
One thing to note, when a text field is in edit mode, it uses something called the field editor for rendering , which is normally a shared instance of NSTextView that is owned by the window and basically appears in front of the text field during editing.

Finder like coloured labels

OS X Finder has this nice feature to colour-label files. I'm thinking of using a similar feature in my app (that is: use this in an NSTableView/NSOutlineView, not looking to highlight items in Finder from my app). Is this ability somehow available through any of the default user interface classes or would it require a custom implementation?
I have experimented with setting NSTextFieldBezelStyle to NSTextFieldRoundedBezel but this seems to kill the ability to draw a background colour and also defaults to a grey border.
Have a look at the NSURL NSURLLabelColorKey, which is one of the attributes you can set for a URL. You can set these values with setResourceValues:error:
After Edit: Sorry, I misinterpreted the question. I think the easiest way is to use a view based table and put a borderless label inside an NSBox of the custom type. You can give the box rounded corners and a background color with no border, and that looks just like the finder label.
Download the Apple SourceView sample app. It's an NSOutlineView that uses a custom NSTextFieldCell for the drawing; tweak that to draw your custom colors.

Background for Mac OS X app and other elements like NSButton, NSTabView

I changed the background color for my app, but other elements keep the same background color.
Looks like I missed some easy configuration, bsc for NSTabViewItems item colors is deprecated by docs, and using current theme...
You can't easily adjust the tint of the standard controls. You're going to have to subclass and override the drawing code for each of the elements.
Also, may I humbly suggest that you leave it the default color?
U may use Core Animation layer in IB. Choose your object (for example button),
open the view effects inspector (⎇⌘8), set checkbox with your object, add "content filters"
color monochrome and set color! That is all!

Making an NSButton resize its image (Cocoa OSX)

I could not find a way in the documentation to tell an NSButton to resize its image to fill up the whole button. Is there a way to do this programatically?
The closest you'll get is -setImageScaling: ... look up the constants to see how the image will be scaled within the button cell, given its bordered state and bezel type.
If you're looking to replace the standard button entirely with your image (ie, the button cell doesn't draw itself at all - your image serves as the entire visual representation), turn off the border (-setBordered:).
All of these options can be configured in IB as well. A tip: in IB, hover the mouse over any setting in the inspector panel - most if not all give you a hint that shows what method controls the behavior affected by the setting's control.

Resources