开发者

changing label size and position runtime tableview

开发者 https://www.devze.com 2023-01-20 09:53 出处:网络
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 truncatesand the positions o

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开发者_StackOverflow社区 below the label which size has changed so that no label overlap each other.

Thanks..


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];
0

精彩评论

暂无评论...
验证码 换一张
取 消