Is there an easy way to combine text and icon in NSCell in Cocoa?

I am trying to create a very simple picklist widget based on NSOutlineView. However, I'm having a hard time figuring out how to display the icon and shortcut next to it, which is indeed the expected behavior in all major implementations of this kind of widget (iTunes, mail, Finder, ...).

So far, I just link two separate cells, but then when I expand the tree, the icon cell gets larger and a gap appears between the icon and its accompanying label. I know that I can probably overcome this problem by extending NSCell and providing a custom class, but since what I am trying to achieve is really standard, I cannot accept that there is no simpler solution.

Candide

+2


source to share


2 answers


Unfortunately, there is no text and icon cell you can just use, fresh out of the box as you'd like. However, when I was working on the project, I found that Apple released sample code that implements this, as it is such a common idiom.

It can be found here, specifically ImageAndTextCell.h / m



It will help teach you UI customization by reading this example, but after scratching it, just drop the ImageAndTextCell right into your project, you should just fine.

+6


source


You need to create ImageAndTextcell to combine text and icon. you can create ImageAndTextcell as follows Example Project



0


source







All Articles