UILabel is not auto-shrinking text to fit label size

后端 未结 17 609
感动是毒
感动是毒 2020-12-04 06:53

I have this strange issue, and im dealing with it for more than 8 hours now.. Depending on situation i have to calculate UILabels size dynamically,
e.g

17条回答
  •  独厮守ぢ
    2020-12-04 07:52

    Two years on, and this issue is still around...

    In iOS 8 / XCode 6.1, I was sometimes finding that my UILabel (created in a UITableViewCell, with AutoLayout turned on, and flexible constraints so it had plenty of space) wouldn't resize itself to fit the text string.

    The solution, as in previous years, was to set the text, and then call sizeToFit.

    -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
    {
        . . .
        cell.lblCreatedAt.text = [note getCreatedDateAsString];
        [cell.lblCreatedAt sizeToFit];
    }
    

    (Sigh.)

提交回复
热议问题