Resizing NSCollectionView to fit inner items?

我的未来我决定 提交于 2019-12-09 23:31:50

问题


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 ;


回答1:


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!




回答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



来源:https://stackoverflow.com/questions/14431097/resizing-nscollectionview-to-fit-inner-items

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!