调整NSCollectionView大小以适合内部项目? [英] Resizing NSCollectionView to fit inner items?
问题描述
如何调整NSCollectionView的大小以适应我所有项目的大小?
How can I resize my NSCollectionView to fit the size of all my items ?
我试过这样的:
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)];
,我得到的结果是一个可怕的结果:collectionView被扭曲。它先前小于父视图,并且已扩展为填充父视图。
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.
注意:我删除了集合视图的滚动条,内部项目是NSBox。
NB : I removed the scrollbars of the collection view and inner items are NSBox.
我没有任何调整大小;
Ps : this what I have without any resizing ;
>
推荐答案
我的第一种方法不是那么糟糕。
Well my first approach wasn't that bad.
我只需要使用 [[self view] setFrame:]
,而不是 [self view] setBoundsSize:]
调整 NSCollectionView
I just had to use [[self view] setFrame:]
instead of [[self view] setBoundsSize:]
to resize the NSCollectionView
这篇关于调整NSCollectionView大小以适合内部项目?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!