Resize view of NSCollectionViewItem

早过忘川 提交于 2020-01-04 09:16:50

问题


How do I programatically set the size of a view of an NSCollectionViewItem?

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

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.


回答1:


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.



来源:https://stackoverflow.com/questions/1627917/resize-view-of-nscollectionviewitem

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