How to show a light reasonable cell selected image / color ?


i'm using table 1 row , uitableviewcellaccessorydisclosureindicator allow selection of value. i'm using disabled button show stretched image in cell.

however, selectedbackgroundview can't seem show other dark blue color or image, uitableviewcellselectionstylegray.

can't understand why seems complicated.

can offer me advice ?

tia
 

if want customise selected background colour possible, rather more involved might (see seloc tech wiki app in signature example: uses uitableviews lot customised colours: selected highlights green).

first of setup cell correctly:

code:
  // called cell table view.  if required create cell , setup required customisation  - (uitableviewcell *)tableview:(uitableview *)tableview cellforrowatindexpath:(nsindexpath *)indexpath  {	  	static nsstring *myidentifier = @"myidentifier";  	  	// try retrieve table view now-unused cell given identifier  	uitableviewcell *cell = [tableview dequeuereusablecellwithidentifier:myidentifier];  	  	// if no cell available, create new 1 using given identifier  	if (cell == nil)  	{  		// 3.0 changed: initwithframe:reuseidentifier: depricated replace suggested new method  		cell = [[[uitableviewcell alloc] initwithstyle:uitableviewcellstyledefault reuseidentifier:myidentifier] autorelease];  		// want have green text green highlights match our overall branding/theme  		cell.textlabel.textcolor = seloc_green;  		cell.selectedbackgroundview = [[[colourabletablecellbackgroundview alloc] init] autorelease];  		cell.selectedbackgroundview.clearscontextbeforedrawing = no;  		cell.selectedbackgroundview.backgroundcolor = [uicolor clearcolor];  		((colourabletablecellbackgroundview *) cell.selectedbackgroundview).cellbackgroundcolor = seloc_green;  	}  	[cell.backgroundview setneedsdisplay];  	  	return cell;  }  
note seloc_green #define uicolor.

need custom view:

.h
code:
  //  //  colourabletablecellbackgroundview.h  //  seloctechwiki  //  //  created robbie duncan on 14/03/2010.  //  copyright 2010 robbie duncan. rights copy, modify , distribute source code , compiled application granted seloc.  other rights reserved.  //  //  custom view draw background of table cell.  can control colours.  //  #import <foundation/foundation.h>  //  // need know sort of shape our cell : if in grouped mode need rounded corners.  in case set correctly.  if table in non-grouped mode set middle  typedef enum  {      customcellbackgroundviewpositiontop, // top cell in group      customcellbackgroundviewpositionmiddle, // middle cell in group or non-grouped table      customcellbackgroundviewpositionbottom, // bottom cell in group      customcellbackgroundviewpositionsingle // single cell in group (so top , bottom)  } customcellbackgroundviewposition;  //  @interface colourabletablecellbackgroundview : uiview  {  	uicolor *cellbackgroundcolor; // background colour table cell.  note backgroundcolor property not used this: if draw rounded corners "show through" color      customcellbackgroundviewposition position; // 1 of above values position  }  //  // make ivars properties  @property (nonatomic, retain) uicolor *cellbackgroundcolor;  @property (assign) customcellbackgroundviewposition position;  //  @end  
.m
code:
  //  //  colourabletablecellbackgroundview.m  //  seloctechwiki  //  //  created robbie duncan on 14/03/2010.  //  copyright 2010 robbie duncan. rights copy, modify , distribute source code , compiled application granted seloc.  other rights reserved.  //  //  custom view draw background of table cell.  can control colours.  //  #import "colourabletablecellbackgroundview.h"  #import "commondefines.h"  //  // "magic number" how round corners. 8 seems match drawing of uitableview  #define round_size 8  //  @implementation colourabletablecellbackgroundview  //  // sythesize properties  @synthesize cellbackgroundcolor;  @synthesize position;  //  #pragma mark uiview methods  //  // draw view  // largely http://stackoverflow.com/questions/400965/how-to-customize-the-background-border-colors-of-a-grouped-table-view  -(void)drawrect:(cgrect)rect   {      cgcontextref c = uigraphicsgetcurrentcontext();      cgcontextsetfillcolorwithcolor(c, [self.cellbackgroundcolor cgcolor]);      cgcontextsetstrokecolorwithcolor(c, [self.cellbackgroundcolor cgcolor]);      cgcontextsetlinewidth(c, 2);  	      if (position == customcellbackgroundviewpositiontop) {  		          cgfloat minx = cgrectgetminx(rect) , midx = cgrectgetmidx(rect), maxx = cgrectgetmaxx(rect) ;          cgfloat miny = cgrectgetminy(rect) , maxy = cgrectgetmaxy(rect) ;          minx = minx + 1;          miny = miny + 1;  		          maxx = maxx - 1;          maxy = maxy ;  		          cgcontextmovetopoint(c, minx, maxy);          cgcontextaddarctopoint(c, minx, miny, midx, miny, round_size);          cgcontextaddarctopoint(c, maxx, miny, maxx, maxy, round_size);          cgcontextaddlinetopoint(c, maxx, maxy);  		          // close path          cgcontextclosepath(c);          // fill & stroke path          cgcontextdrawpath(c, kcgpathfillstroke);                          return;      } else if (position == customcellbackgroundviewpositionbottom) {  		          cgfloat minx = cgrectgetminx(rect) , midx = cgrectgetmidx(rect), maxx = cgrectgetmaxx(rect) ;          cgfloat miny = cgrectgetminy(rect) , maxy = cgrectgetmaxy(rect) ;          minx = minx + 1;          miny = miny ;  		          maxx = maxx - 1;          maxy = maxy - 1;  		          cgcontextmovetopoint(c, minx, miny);          cgcontextaddarctopoint(c, minx, maxy, midx, maxy, round_size);          cgcontextaddarctopoint(c, maxx, maxy, maxx, miny, round_size);          cgcontextaddlinetopoint(c, maxx, miny);          // close path          cgcontextclosepath(c);          // fill & stroke path          cgcontextdrawpath(c, kcgpathfillstroke);                  return;      } else if (position == customcellbackgroundviewpositionmiddle) {          cgfloat minx = cgrectgetminx(rect) , maxx = cgrectgetmaxx(rect) ;          cgfloat miny = cgrectgetminy(rect) , maxy = cgrectgetmaxy(rect) ;          minx = minx + 1;          miny = miny ;  		          maxx = maxx - 1;          maxy = maxy ;  		          cgcontextmovetopoint(c, minx, miny);          cgcontextaddlinetopoint(c, maxx, miny);          cgcontextaddlinetopoint(c, maxx, maxy);          cgcontextaddlinetopoint(c, minx, maxy);  		          cgcontextclosepath(c);          // fill & stroke path          cgcontextdrawpath(c, kcgpathfillstroke);                  return;      }else if (position == customcellbackgroundviewpositionsingle)  	{          cgfloat minx = cgrectgetminx(rect) , midx = cgrectgetmidx(rect), maxx = cgrectgetmaxx(rect) ;          cgfloat miny = cgrectgetminy(rect) , midy = cgrectgetmidy(rect) , maxy = cgrectgetmaxy(rect) ;          minx = minx + 1;          miny = miny + 1;  		          maxx = maxx - 1;          maxy = maxy - 1;  		          cgcontextmovetopoint(c, minx, midy);          cgcontextaddarctopoint(c, minx, miny, midx, miny, round_size);          cgcontextaddarctopoint(c, maxx, miny, maxx, midy, round_size);          cgcontextaddarctopoint(c, maxx, maxy, midx, maxy, round_size);          cgcontextaddarctopoint(c, minx, maxy, minx, midy, round_size);  		          // close path          cgcontextclosepath(c);          // fill & stroke path          cgcontextdrawpath(c, kcgpathfillstroke);                          return;           	}  }  //  @end  
 


Forums iPhone, iPad, and iPod Touch iOS Programming


  • iPhone
  • Mac OS & System Software
  • iPad
  • Apple Watch
  • Notebooks
  • iTunes
  • Apple ID
  • iCloud
  • Desktop Computers
  • Apple Music
  • Professional Applications
  • iPod
  • iWork
  • Apple TV
  • iLife
  • Wireless

Comments