Question

How can I resize my NSCollectionView to fit the size of all my items ?

I tried something like that :

    float height=0;
for(int i=0;i<[drives count]; i++) {
    height += [[[collectionView itemAtIndex:i] view] bounds].size.height;
}
NSLog(@"%lg", height);
[[self view] setBoundsSize:NSMakeSize(300, height)];

and all I got was a horrible result : the collectionView was distorted. It was previously smaller than the parent view and with that it expanded to fill the parent view.

NB : I removed the scrollbars of the collection view and inner items are NSBox.

Ps : this what I have without any resizing ;

enter image description here

Was it helpful?

Solution 2

Well my first approach wasn't that bad.

I just had to use [[self view] setFrame:] instead of [[self view] setBoundsSize:] to resize the NSCollectionView

OTHER TIPS

Have a look at this question: Can NSCollectionView autoresize the width of its subviews to display one column I think that may help solve you issue!

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