I am an Android developer trying to learn iOS development in Swift. I was wondering how you achieve "wrap_content" in Xcode. Any ideas? What are the variables to change in the attribute inspector?
The Android docs state that wrap_content
:
tells your view to size itself to the dimensions required by its content.
This sounds analogous to what Apple calls the intrinsic content size. They detail how to configure it in the attribute inspector here.
To override the intrinsic content size of a UIView
(such as a UILabel
or a UIButton
), you would simply have to override UIView
's intrinsicContentSize()
method.
Try following code that fits textView's frame according to it's contained data-
let fixedWidth = textView.frame.size.width
textView.sizeThatFits(CGSize(width: fixedWidth, height: CGFloat.max))
let newSize = textView.sizeThatFits(CGSize(width: fixedWidth, height: CGFloat.max))
var newFrame = textView.frame
newFrame.size = CGSize(width: max(newSize.width, fixedWidth), height: newSize.height)
textView.frame = newFrame;
u can do this in storyboard
be sure no other constraint defined for the view which limit the width!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With