i have been trying find way adjust height of uitextview on place not find answer. so, asking help. not using storyboard make constraints. how make height of uitextview dynamic based on content size? thank help! have attached image show how textview looks like.
scrollview.addsubview(itemtitleview) itemtitleview.topanchor.constraintequaltoanchor(itemimage.bottomanchor, constant: 80).active = true itemtitleview.widthanchor.constraintequaltoanchor(itemimage.widthanchor).active = true itemtitleview.heightanchor.constraintequaltoconstant(56).active = true itemtitleview.centerxanchor.constraintequaltoanchor(view.centerxanchor).active = true
try using extension string. give height need if know width be. need width , font , should work.
extension string { func heightwithconstrainedwidth(width: cgfloat, font: uifont) -> cgfloat { let constraintrect = cgsize(width: width, height: cgfloat.max) let boundingbox = self.boundingrectwithsize(constraintrect, options: nsstringdrawingoptions.useslinefragmentorigin, attributes: [nsfontattributename: font], context: nil) return boundingbox.height } }
Comments
Post a Comment