iphone - UILabel - issue with flexible size and fixed sapce -


i'm trying view information on 3 different lables; first. title two. release date three. description

between title , release date have 2 blank lines. when title gets more 3 lines written on date of publication. here picture (the bold line pub date label): title gets on pubdate

and when description label large amount of text thats happend: enter image description here

this how should be:

enter image description here

so questions: 1. how can save fixed space between title , pubdate? (no matter how lines title remain between 2 fixed space) 2. why description move down when gets large amount of text? how can fixed place?

i want save space between 3 labels no matter how lines each has.

here code far:

- (void)viewdidload {       [super viewdidload];      [_scroller setscrollenabled:yes];     [_scroller setcontentsize:cgsizemake(320, 600)];       self.lbldescription.text = self.description;     self.lbltitle.text = self.stitle;     self.lblpubdate.text = self.pubdate;       self.lbltitle.numberoflines = 0;     [self.lbltitle sizetofit];     self.lbltitle.textalignment = uitextalignmentright;     cgrect titlefram = self.lbltitle.frame;     titlefram = cgrectmake(titlefram.origin.x, titlefram.origin.y, 280, titlefram.size.height);     self.lbltitle.frame = titlefram;      self.lbldescription.numberoflines = 0;     [self.lbldescription sizetofit];      [self resizeheighttofitforlabel:self.lbltitle];     [self resizeheighttofitforlabel:self.lbldescription];   } -(void)resizeheighttofitforlabel:(uilabel *)label {     cgrect newframe         = label.frame;     newframe.size.height    = [self heightforlabel:label withtext:label.text];     label.frame             = newframe; }  -(cgfloat)heightforlabel:(uilabel *)label withtext:(nsstring *)text {     cgsize maximumlabelsize     = cgsizemake(290, flt_max);      cgsize expectedlabelsize    = [text sizewithfont:label.font                                    constrainedtosize:maximumlabelsize                                        linebreakmode:label.linebreakmode];      return expectedlabelsize.height; } 

what best way done? thanks..

try this,

- (void)viewdidload {     [super viewdidload];      [_scroller setscrollenabled:yes];     [_scroller setcontentsize:cgsizemake(320, 600)];      //use way     [self positionlabel:self.lbltitle withtext:self.stitle withy:10];     [self positionlabel:self.lblpubdate withtext:self.pubdate withy:cgrectgetmaxy(self.lbltitle.frame)+10 ];     [self positionlabel:self.lbldescription withtext:self.description withy:cgrectgetmaxy(self.lblpubdate.frame)+10 ];  }  -(void)positionlabel:(uilabel*)lbl withtext:(nsstring*)text withy:(cgfloat)y {     lbl.textalignment = uitextalignmentright;     lbl.text = text;     lbl.numberoflines = 0;     lbl.linebreakmode = nslinebreakbywordwrapping;     cgsize size = [self calculatesize:lbl];     //fixed     [lbl setframe:cgrectmake(10 , y , (size.width>310)?size.width:310 , size.height)];  }  -(cgsize)calculatesize:(uilabel*)lbl {     cgsize size = [lbl.text sizewithfont:lbl.font                        constrainedtosize:cgsizemake(310, maxfloat)                            linebreakmode:uilinebreakmodewordwrap];     return size; } 

Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -