Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Changing the background color of an NSCollectionView

Tags:

cocoa

Is it a chance to programatically change the background color of NSCollectionView?

I was trying subclassing.. but not working..

 @interface CollectionViewBg : NSCollectionView

in .m

 [self setBackgroundColors:[NSArray arrayWithObjects:[NSColor blueColor], nil]];
like image 323
Justin Boo Avatar asked Nov 12 '11 21:11

Justin Boo


1 Answers

In .m, remove this line :

 [self setBackgroundColors:[NSArray arrayWithObjects:[NSColor blueColor], nil]];

And use this code:

- (void)drawRect:(NSRect)dirtyRect{

[[NSColor blueColor] setFill];
NSRectFill(dirtyRect);

}

Also don't forget to change class of NSCollectionView object in IB to CollectionViewBg.

Hope this helps :)

like image 169
Devarshi Avatar answered Sep 22 '22 08:09

Devarshi