1

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

Matthieu Riegler
  • 31,918
  • 20
  • 95
  • 134
  • Do you mean that you got rid of the scroll view that interface builder adds automagically? If so, don't do that... It needs that view to draw properly, otherwise it will be as big as its expanded items. – Grady Player Jan 21 '13 at 06:43
  • I want it to display all my items without scrolling ! – Matthieu Riegler Jan 21 '13 at 07:14

2 Answers2

0

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!

Community
  • 1
  • 1
0

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

Matthieu Riegler
  • 31,918
  • 20
  • 95
  • 134