iphone - UILabel in custom cell will not increase height dynamically -
i've got custom cell contains 3 uilabels. last label contain text has embedded \n's data in cell listed 1 item per line. know number of lines needed , know each line needs 15 pixels high. code i've got change size of label here:
//set cell static nsstring *cellidentifier = @"cell"; customhistorycell *cell = (customhistorycell *)[tableview dequeuereusablecellwithidentifier:cellidentifier]; if (cell == nil) { cell = [[[customhistorycell alloc] initwithframe:cgrectzero reuseidentifier:cellidentifier] autorelease]; } cell.probeinfo.linebreakmode = uilinebreakmodewordwrap; cell.probeinfo.numberoflines = 0; cell.probeinfo.text = theprobes; [cell.probeinfo setadjustsfontsizetofitwidth:yes]; cgrect newframe = cell.probeinfo.frame; newframe.size.height = nadditionallabelheight*15; cell.probeinfo.frame = newframe;
theprobes contains text \n's , nadditionallabelheight contains number of lines. i've set background color grey can see if label correctly sized , doesn't change it's height. can see i'm doing wrong?
here's code custom cell .h file in case may help:
@interface customhistorycell : uitableviewcell { uilabel *_stokername; uilabel *_smokedatetime; uilabel *_probeinfo; } @property (nonatomic,retain) uilabel *stokername; @property (nonatomic,retain) uilabel *smokedatetime; @property (nonatomic,retain) uilabel *probeinfo; @end
and here's code custom cell .m file in case may help:
#import "customhistorycell.h" @implementation customhistorycell @synthesize stokername = _stokername; @synthesize smokedatetime = _smokedatetime; @synthesize probeinfo = _probeinfo; - (id)initwithstyle:(uitableviewcellstyle)style reuseidentifier:(nsstring *)reuseidentifier { if (self = [super initwithstyle:style reuseidentifier:reuseidentifier]) { // initialization code self.stokername = [[uilabel alloc]init]; self.stokername.textalignment = uitextalignmentleft; self.stokername.font = [uifont boldsystemfontofsize:20]; self.smokedatetime = [[uilabel alloc]init]; self.smokedatetime.textalignment = uitextalignmentleft; self.smokedatetime.font = [uifont systemfontofsize:12]; self.probeinfo = [[uilabel alloc]init]; self.probeinfo.textalignment = uitextalignmentleft; self.probeinfo.font = [uifont systemfontofsize:12]; self.probeinfo.backgroundcolor = [uicolor graycolor]; [self.contentview addsubview:self.stokername]; [self.contentview addsubview:self.smokedatetime]; [self.contentview addsubview:self.probeinfo]; } return self; } - (void)layoutsubviews { [super layoutsubviews]; cgrect contentrect = self.contentview.bounds; cgfloat boundsx = contentrect.origin.x; cgrect frame; frame= cgrectmake(boundsx+5,5, 300, 25); self.stokername.frame = frame; frame= cgrectmake(boundsx+5,30, 300, 15); self.smokedatetime.frame = frame; frame= cgrectmake(boundsx+5,45, 300, 15); self.probeinfo.frame = frame; } - (void)dealloc { [super dealloc]; } @end
i figured out way handle this. override initwithstyle , passed in nadditionallabelheight variable , used set height of label.
Comments
Post a Comment