简体   繁体   中英

UILabel sizeToFit - Adjust position on object below

I'm writing a screen that has multiple UILabel on it, each one below the other on the screen. One of the labels has multiple lines and I've use [myLabel sizeToFit] along with myLabel.numberOfLines = 0 to enable word wrapping and the label to stretch its height to fit all the text. This works perfectly, however, all the other UILabels that I have positioned below this multi-line label in Interface Builder do not adjust their position in relation it. Is there a way to automatically get the other UILabel objects to adjust their position in relation to the stretched multi-line label?

Thanks

Brian

环顾四周,最好的解决方案是将其实际实现为具有静态单元格的UITableView。

I'd love to be proven wrong, but I think the only way to achieve this is to subclass the parent view of those UILabels and override layoutSubviews method. I had very similar problem some time ago, and this is what I ended up doing. I cannot find this class in my resources anymore, but I remember it was working pretty well even when the view was loaded from xib.

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