UIlabel gets shrink on scrolling UiTableView

后端 未结 4 1492
天涯浪人
天涯浪人 2020-12-11 08:52

I have two UILabel in side of UICell, which contains dynamic text so i need to resize its frame according to content, for which im using [str

4条回答
  •  爱一瞬间的悲伤
    2020-12-11 09:42

    In your case you need to set the height of cell based on the label.

    Check the link :

    http://dcraziee.wordpress.com/2013/05/22/calculate-size-of-uillabel-base-on-text-in/

    There is a function named

    -(CGFloat)getHeightForLabel:(NSString *)_str font:(UIFont *)fontOfObject
    

    Use that function to calculate height as :

    -(float)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
    {
        CGFloat _height  = [self getHeightForLabel:self.label.text font:[self.label font]];
        return _height;
    }
    

    and do the same while creating and adding label in the cell. I hope this will help.

提交回复
热议问题