简体   繁体   中英

Auto Layout, custom UITableViewCell, growing labels

I'm trying to solve this Auto Layout puzzle with a custom UITableViewCell which contains two labels that may grow vertically depending on their content ie number of lines. I've almost got it right, except that one label in one cell does not grow as expected! Please see screenshot where highlighted in red dashed line – the label does not end with a bracket, its text is clipped instead.

在此处输入图片说明在此处输入图片说明 Please find the simple Xcode project here.

In my case there are two multiline labels and not just one as in other posts, and so there are 2 elements that effect the height of a cell. But regardlesss of that the soluion is to force the cell to do its layout. So after calling dequeueReusableCellWithIdentifier() to get the cell, just add:

// fix for iOS lauout bug
cell.setNeedsLayout()
cell.layoutIfNeeded()

All starting and ending brackets are visible ie to text clipping :-) 在此处输入图片说明

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM