调整NSCollectionViewItem的视图大小 [英] Resize view of NSCollectionViewItem
问题描述
如何以编程方式设置NSCollectionViewItem的视图大小?
How do I programatically set the size of a view of an NSCollectionViewItem?
我尝试在NSCollectionView子类中这样做:
I tried doing this in an NSCollectionView subclass:
@implementation CustomCollectionView
- (NSCollectionViewItem *)newItemForRepresentedObject:(id)object {
NSCollectionViewItem *newitem = [[self itemPrototype] copy];
[newitem setRepresentedObject:object];
NSView *itemview = [newitem view];
[itemView setFrame:NSMakeRect([itemView frame].origin.x, [itemView frame].origin.y, [itemView frame].size.width, 500)];
return newitem;
}
@end
但是此代码无效。我尝试将用于NSCollectionViewItem的NSView子类化,并将setFrame:添加到initWithCoder方法中,但这样做时出现EXC BAD ACCESS崩溃。
However this code has no effect. I tried subclassing my NSView that I use for the NSCollectionViewItem, and adding setFrame: to the initWithCoder method, but I get an EXC BAD ACCESS crash when I do that.
推荐答案
您可以从Steven Degutis签出此开源NSCollectionView替代方案,巧合的是,我认为它今天才刚刚发布到GitHub(我今天通过Twitter注意到了):
You might checkout this open source NSCollectionView alternative from Steven Degutis which, coincidentally I think was just posted to GitHub today (I noticed it today via Twitter):
http://github.com/sdegutis/SDListView
看起来它允许您放置不同高度的物品。
Looks like it allows you to have items with different heights.
这篇关于调整NSCollectionViewItem的视图大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!