uitableview - iOS UILabel width doesn't fit inside table cell -


i'm new ios development. have issue when trying put labels inside uitableviewcell. text keeps going out of cell. add needed constraints doesn't work. here setup , code:

title label attributes: number of lines-0, line breaks-word wrap 

viewdidload():

self.tableview.estimatedrowheight = 68.0; self.tableview.rowheight = uitableviewautomaticdimension; 

cellforrowatindexpath():

uilabel *titlelabel = (uilabel*)[cell viewwithtag:100]; titlelabel.text = @"why long text out of cell? quick brown fox jumps on lazy dog. quick brown fox jumps on lazy dog. quick brown fox jumps on lazy dog. quick brown fox jumps on lazy dog. quick brown fox jumps on lazy dog."; 

i'm using xcode 6.2 , ios 8.2.

thanks help.

screenshot:
enter image description here

cell prototype: enter image description here

title label constraints:
enter image description here

you need 2 things in order keep text inside label boundries , in cell.

  1. if width of label fixed in case cell's height depends on height of label(which derived it's content). have provided estimatedrowheight , rowheight uitableviewautomaticdimension. ok.
  2. the width of label should limited before/ till reaches extreme right of cell. please ensure if label's width flexible should hooked right side well.

alternatively write code using below api calculate label's height based on content of label. determine height of cell. , while creating cell assign text label.

for ios 7 , above:

#define labels_max_height             10000.0f   cgsize constraintsize = cgsizemake(label.frame.size.width, labels_max_height);  nsattributedstring *attributedtext = [[[nsattributedstring alloc] initwithstring:text attributes:@{nsfontattributename: label.font}] autorelease];         cgrect rect = [attributedtext boundingrectwithsize:constraintsize                                                    options:nsstringdrawinguseslinefragmentorigin                                                    context:nil];         strsize = rect.size; 

Comments

Popular posts from this blog

node.js - Mongoose: Cast to ObjectId failed for value on newly created object after setting the value -

gradle error "Cannot convert the provided notation to a File or URI" -

python - NameError: name 'subprocess' is not defined -