简体   繁体   English

iOS Swift 3-自动布局,更改高度取决于文本或视图大小

[英]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). 这是uitableview中的一个单元格,我使用带有排除路径的uitextview来使文本围绕正确的视图(底部带有图像和文本的视图)流动。 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. 我不确定如何使用排除路径计算uitextview的高度,以便与正确的视图进行比较并确定用于单元格设置的高度。

My cell is setup like this: 我的单元格设置如下:

  • cell has 3 containers 牢房有3个容器

  • container 1 is header which is a label 容器1是标头,它是标签

  • container 2 is the image above which contains a text view and on the right is a custom view with photo & text below it 容器2是上面的图像,其中包含一个文本视图,右边是一个自定义视图,下面是照片和文本

  • container 3 can be images, text or empty 容器3可以是图片,文本或空白

How should I setup autolayout for this? 我应该如何为此设置自动布局? I'm using Swift 3 & autolayout 我正在使用Swift 3和自动布局

Provide the constraints to the text view in table view cell. 在表视图单元格中为文本视图提供约束。 And in viewDidLoad of your tableView controller set below properties: 并在tableView控制器的viewDidLoad中设置以下属性:

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/ 请参阅以下链接: http : //candycode.io/self-sizing-uitextview-in-a-uitableview-using-auto-layout-like-reminders-app/

Hope this would be helpful! 希望这会有所帮助!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在iOS 8 swift中更改Button文本大小 - How to change Button text size in iOS 8 swift 在启用自动布局和尺寸类别的情况下更改视图宽度 - Change view width with autolayout and size class enabled iOS Autolayout视图高度基于较大的子视图高度 - iOS Autolayout view height based on larger subview height UILabel 文本属性设置为 nil 或 &quot;&quot; 使 UILabel 从视图中消失(Swift / Autolayout / iOS9.1) - UILabel text property when set to nil or "" makes UILabel disappear from view (Swift / Autolayout/ iOS9.1) 在ios swift中使用autolayot根据html文本更改webview高度 - Change webview height based on html text using autolayot in ios swift 更改 html 中图像的宽度和高度 swift IOS 中的文本 - Change width and height of image in html text in swift IOS Swift:更改 UINavigationController 视图的高度 - Swift: Change height of UINavigationController view Swift iOS-如何设置UIView的高度锚&lt;=到标签的内在文本大小? &#39;NSLayoutConstraint&#39;不能转换为&#39;Bool&#39; - Swift iOS -How to set UIView's Height Anchor <= To A Label's Intrinsic Text Size? 'NSLayoutConstraint' is not convertible to 'Bool' 使用自动布局的自定义视图的动态高度 - dynamic height of custom view with Autolayout 视图和超级视图自动布局的比例高度 - proportional height of view and superview autolayout
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM