简体   繁体   English

更改 TextView 高度 - iOS

[英]change TextView height - iOS

i have a xib file as tableview header cell which i want it to be self size.我有一个 xib 文件作为 tableview 标题单元格,我希望它是自我大小。 inside xib, i have a text view that i want to change its height on a button press.在xib 中,我有一个文本视图,我想在按下按钮时更改其高度。 when btn is pressed, the textview's height should be the size to fit the text inside and when btn pressed again, it should resize to just two lines of text.当 btn 被按下时,textview 的高度应该是适合里面文本的大小,当 btn 再次按下时,它应该调整为只有两行文本。

在此处输入图片说明

i used these lines of code in my btn action我在 btn 操作中使用了这些代码行

    let contentSize = self.content.sizeThatFits(self.content.bounds.size)
    var frame = self.content.frame
    frame.size.height = contentSize.height
    self.content.frame = frame

it expands the textview but textview overlaps to elements below it.它扩展了 textview 但 textview 与其下方的元素重叠。 using two lines of code below for self sizing header makes every thing worse and it shows only two lines of textview and cm, like and others disappear.使用下面的两行代码进行自我调整标题会使一切变得更糟,它只显示两行 textview 和 cm,像和其他人一样消失。

    tableView.estimatedSectionHeaderHeight = 115.0
    tableView.sectionHeaderHeight = UITableViewAutomaticDimension

how can i solve this?我该如何解决这个问题?

可以使用 autolayout + UITableViewAutomaticDimension 来做到这一点,请查看: http ://candycode.io/self-sizing-uitextview-in-a-uitableview-using-auto-layout-like-reminders-app/

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

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