简体   繁体   中英

How to resize a view based on its intrinsic content?

Let's say I have a view with a multi-line label inside (subview). As I add dynamic text, I want the label as well as the parent view to grow in size so that all the text always appears without being truncated. This is something I've been struggling with for some reason. I want the outer view to push down any trailing views as it grows. How can I do this using xcode 9 swift 4?

step 1: In storyboard put the label inside the view and give number of lines to '0'

step 2: give the label top,bottom,leading,trailing constraints to the view for example '0' spacing in all sides.

step 3: Now give the view x,y positions and width , no need to give the height of the view it will automatically infer it from the label.

The intrinsic property of the label will automatically pushes the height of the view with respective to the content.

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