Finder like coloured labels - cocoa

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.

Related

How do you add a toolbar to the bottom of an NSTableView?

Check the following image, how can I add this kind of bar to my own NSTableViews? Other uses are in the network preferences app. What's the magic trick to make this work?
I don't think there is any "magic trick." This is something you will have to implement yourself.
It looks like a group of Gradient style NSButtons placed below the table view. An NSSegmentedControl in Small Square style would work too.

Creating NSToolbar style buttons

Is there a bevel style that can replicate NSToolbar style of buttons that are used, for instance, in the Safari's preferences window to switch between different panes?
I need to replicate NSToolbar in an NSView using NSButtons. I understand that I should probably be using NSTabView, but I'd like to implement the look of xcode's left pane. Any tips here would be appreciated greatly.
There's nothing built-in, you'd have to create the images yourself. However, replicating the behaviour is straightforward.
You could simply use a single-row NSMatrix of NSButton objects. Just give the buttons an image and an alternate image (for the highlighted state) and set the matrix mode to NSRadioModeMatrix.

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!

Text Field rendering

I am trying to build a really simple NSTextField with Interface Builder (XCode 4), but the rendering is really weird with default values:
The only setting I changed is the border style:
My question:
How to display a neat Text Field “squared but with rounded corners”, like in Safari:
How to remove that “overflow:hidden” (sorry for the CSS description) which cuts the focus? < Interface Builder bug, fixed.
Should I design my own, image-based component?
Thank you!
I think I've found exactly what you're looking for. Here's what it looks like:
It's called SSTextField. Download the subclass here: http://cocoatricks.com/2010/06/a-better-looking-text-field/
What you've got at the top is a NSSearchField, which is designed for filtering/searching.
Likely the reason why the focus ring is cut off is because you've got it inside a box or overlapping another object. Don't do that.
There are no standard rounded-corner (as opposed to rounded-end) text fields; if you want one, you'll need to subclass NSTextField yourself, or just wait for Lion where the standard text field will have rounded corners.
Rounded rectangle text fields are pretty straightforward and don't require subclassing the control. Instead you can simply override the way the background CALayer of the control is drawn.
Choose the square-cornered field shape, add the QuartzCore framework to your project, and then #import <QuartzCore/QuartzCore.h>. In your controller's viewDidLoad method you'll modify the text field's layer's cornerRadius property, a la:
myTextField.layer.cornerRadius = 6.0;
Poof, rounded-rectangle text field!

Is it posible to use free form shapes as windows in OSX?

I want to use a free form shape (e.g. A partially transparent image) as a window backgound without the standard close and maximise buttons. Like the widgets do. Is that possible in OSX? I could not find any info on that or an app that uses this.
Thanks
Yes. You can do this by subclassing NSWindow to make it borderless and transparent. You'll also subclass NSView to draw the visible custom shape, then use an instance of this view as the window's content view. The result will be a window whose only visible parts will be the shape your content view draws.
Here's a good article with an example.

Resources