Question

I have an NSCollectionView. My example subviews are simple, basically a Label with a box around them.

enter image description here

I would like my subviews to resize their width to fit the label length. For example, if we have "banana", "tomato" and "pig", i.e.,

@implementation AppDelegate

- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
{
    // Insert code here to initialize your application
    self.listObjArray = [NSArray arrayWithObjects:@"banana", @"tomato", @"pig", nil];

}

the CollectionView (bound to Array Controller bound to listObjArray) should show

[banana] [tomato] [pig]

instead of

[bana] [toma] [pig ]

enter image description here

How can I do this? As a bonus, I would like the subview to increase in size no larger than the CollectionView width, so that I have I have a really long text, I would end up with

[thisisareallysuperlongkindofst...]
[banana] [tomato] [pig]

No correct solution

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top