简体   繁体   中英

iOS Swift 3 - Autolayout, change height depends on text or view size

I have a view like below image:

在此处输入图片说明

This is a cell in uitableview I use uitextview with exclusion path to make the text flows around the right view (the view with image & text at the bottom). Sometimes the text is short and the right view is longer, but sometimes otherwise. I'm not sure how to calculate the height of uitextview with exclusion path in order to compare with the right view and decide which height is used to set for the cell.

My cell is setup like this:

  • cell has 3 containers

  • container 1 is header which is a label

  • container 2 is the image above which contains a text view and on the right is a custom view with photo & text below it

  • container 3 can be images, text or empty

How should I setup autolayout for this? I'm using Swift 3 & autolayout

Provide the constraints to the text view in table view cell. And in viewDidLoad of your tableView controller set below properties:

self.tableView.estimatedRowHeight = 44
self.tableView.allowsMultipleSelection = true

Refer this link: http://candycode.io/self-sizing-uitextview-in-a-uitableview-using-auto-layout-like-reminders-app/

Hope this would be helpful!

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