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 ;
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!
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
来源:https://stackoverflow.com/questions/14431097/resizing-nscollectionview-to-fit-inner-items