ios - Size UITextView to contents in Swift -
i have seen , tried few solutions online size text view contents nothing seems working. have auto layout on, scrolling disabled, , here code in viewdidload i'm using try , resize text view dynamically.
var frame = abouttext.frame frame.size.height = abouttext.contentsize.height abouttext.frame = frame
i have tried
abouttext.sizetoft() abouttext.layoutifneeded()
edit: tried:
let fixedwidth = abouttext.frame.size.width abouttext.sizethatfits(cgsize(width: fixedwidth, height: cgfloat.max)) let newsize = abouttext.sizethatfits(cgsize(width: fixedwidth, height: cgfloat.max)) var newframe = abouttext.frame newframe.size = cgsize(width: max(newsize.width, fixedwidth), height: newsize.height) abouttext.frame = newframe
technically, because using auto layout, should able use constraints , compression/stretching priorities set text view size contents. text view's natural behavior.
however, if should fail, here code should force size content:
let size = textview.sizethatfits(cgsizemake(width, cgfloat(flt_max))) // width width text view should be, width of parent view - 20 textview.frame = cgrectmake(textview.frame.origin.x, textview.frame.origin.y, size.width, size.height) // may have call view.layoutifneeded()
update ** auto textview sizing uitableview
implement in uitableviewdelegate:
override func tableview(tableview: uitableview, estimatedheightforrowatindexpath indexpath: nsindexpath) -> cgfloat { return uitableviewautomaticdimension }
then constrain text view top , bottom of table view cell. each table view cell should resize fit it's content text.
this video should address problem exactly, helped me lot: https://developer.apple.com/videos/wwdc/2015/?id=231
Comments
Post a Comment