uitableview - Set background color for all UITableViewCells in iOS app -
uitableview - Set background color for all UITableViewCells in iOS app -
what's easiest way set backgroundcolor of uitableviewcells in ios app?
consider app has relatively big number of uitableviewcontroller subclasses. background color specified via web service. using color in each tableviewcontroller not easiest thing do.
perhaps every tableviewcell inherit uitableviewcell subclass color set derived classes? there might easier way.
my recommendation singleton. example:
@interface colorthemesingleton : nsobject @property (strong, atomic) uicolor *tableviewbackgroundcolor; +(colorthemesingleton *)sharedinstance; @end and .m:
#import "colorthemesingleton.h" @implementation colorthemesingleton @synthesize tableviewbackgroundcolor = _tableviewbackgroundcolor; +(colorthemesingleton *)sharedinstance{ static colorthemesingleton *shared = nil; static dispatch_once_t oncetoken; dispatch_once(&oncetoken, ^{ shared = [[colorthemesingleton alloc] init]; }); homecoming shared; } -(id)init{ if ((self = [super init])){ _tableviewbackgroundcolor = [uicolor whitecolor]; // default color } homecoming self; } @end then after if(cell==nil){} in tableview:cellforrowatindexpath: add:
cell.backgroundcolor = [colorthemesingleton sharedinstance].tableviewbackgroundcolor; and when load color web, set value of property fetched color. next time cell runs through tableview:cellforrowatindexpath: color new color.
so add together #import"" , cell.backgroundcolor = tableview's datasource. me that's lot improve changing uitableviewcell's class on every controller.
ios uitableview background-color
Comments
Post a Comment