objective c - How do I change the color or a NSTableCellView for each cell of an NSOutlineView -


i've looked @ number of questions can't find good solution view-based nsoutlineview

coloring nstableview text per row

change color of nstableviewcell

custom background colors nstablecellview

i'm trying set each row whatever color want. i've read somewhere need subclass nstablerowview i've done.

according appledocs, see following methods:

– drawbackgroundinrect: – drawdraggingdestinationfeedbackinrect: – drawselectioninrect: – drawseparatorinrect: 

how go setting background color individual rows? going wrong route above?

edit: below (also edited title)

since i'm using nsoutlineview , not nstableview, when change background color of cells image looks following. disclosure arrows left not colored. there way change color of whole row nsoutlineview?

this

you subclass nstableviewcell, , add method sets color.

nstableviewcell subclass of nsview, in subclass, add following method:

- (void)setbackgroundcolor {     self.layer.backgroundcolor = cgcolorcreategenericrgb(0, 0, 0, 1.0f); // or whatever color } 

or that. you'll want have color param method. then, in table view delegate, can set color depending on row index passed delegate method. example:

- (uitableviewcell *)tableview:(uitableview *)table cellforrowatindexpath:(nsindexpath *)indexpath {     uitableviewcell *cell = [table dequeuereusablecellwithidentifier:@"cell"];     if (cell == nil)         cell = [[uitableviewcell alloc] initwithstyle:uitableviewcellstyledefault reuseidentifier:@"cell"];      if (indexpath.row % 2) {         [cell setbackgroundcolor:[uicolor redcolor]]; // or     } } 

Comments

Popular posts from this blog

image - ClassNotFoundException when add a prebuilt apk into system.img in android -

I need to import mysql 5.1 to 5.5? -

Java, Hibernate, MySQL - store UTC date-time -