views:

17

answers:

1

I am using customCell in UITableView my cell has diffrent UILabel in customCell

I want to change the size of the labels according the text to be displayed so that no text truncates and the positions of the labels below the label which size has changed so that no label overlap each other.

Thanks..

A: 

If you're subclassing UITableViewCell you can layout your custom labels in layoutSubviews:

- (void)layoutSubviews {
    [super layoutSubviews];
    myCustomLabel.frame = CGRectMake( 5, 5, self.bounds.width - 5, 40 );
    myOtherCustomLabel.frame = CGRectMake( CGRectGetMinX( myCustomLabel.frame ), CGRectGetMaxY( myCustomLabel.frame ), myCustomLabel.frame.size.width, 30 );
}

To calculate the size needed for text, use sizeWithFont:

CGSize textSize = [textString sizeWithFont:labelFont constrainedToSize:CGSizeMake( widthOfCell, CGFLOAT_MAX ) lineBreakMode:UILineBreakModeWordWrap];
aegzorz