iphone - how to set text of titleForHeaderInSection to AlignmentCenter -
i used follow code set title @ group tableview title header,but default text alignmentleft,how alignmentcenter?
- (nsstring *)tableview:(uitableview *)tableview titleforheaderinsection:(nsinteger)section { if(section==0){ return nslocalizedstring(@"more_titlehead_one", nil); }else if (section==1){ return nslocalizedstring(@"more_titlehead_two", nil); }else{ return nslocalizedstring(@"more_titlehead_three", nil); } }
try this,
- (uiview *)tableview:(uitableview *)tableview viewforheaderinsection:(nsinteger)section { uilabel * sectionheader = [[[uilabel alloc] initwithframe:cgrectzero] autorelease]; sectionheader.backgroundcolor = [uicolor clearcolor]; sectionheader.textalignment = uitextalignmentcenter; sectionheader.font = [uifont boldsystemfontofsize:10]; sectionheader.textcolor = [uicolor whitecolor]; switch(section) { case 0:sectionheader.text = @"title one"; break; case 1:sectionheader.text = @"title two"; break; default:sectionheader.text = @"title other"; break; } return sectionheader; }
set default height header,
- (cgfloat)tableview:(uitableview *)tableviewheightforheaderinsection:(nsinteger)section { switch(section) { case 0: case 1: default:return 20; } }
Comments
Post a Comment