I started using Xcode with storyboards and do not normally change attributes of objects using swift. However, I have two UITextView objects defined in my storyboard and both are defined in storyboard with width 316 and height 36. I am attempting to resize the height to contain the different text strings but I am having problems with the different width of the textviews at runtime. When I examined the storyboard code I found that the frames are different. One is w 271 and h 117 whereas the other is w 240 and h 128 h. (Their x and y settings are also different.)
Can anyone explain how I can fix this in storyboard? How does it get set in the first place? Will I have to change the storyboard values manually? Below are examples:
<textView autoresizesSubviews="NO" opaque="NO" clearsContextBeforeDrawing="NO" userInteractionEnabled="NO" contentMode="scaleAspectFit" ambiguous="YES" misplaced="YES" bounces="NO" scrollEnabled="NO" showsHorizontalScrollIndicator="NO" showsVerticalScrollIndicator="NO" delaysContentTouches="NO" canCancelContentTouches="NO" bouncesZoom="NO" editable="NO" translatesAutoresizingMaskIntoConstraints="NO" id="Lje-0i-uhe" userLabel="menu textview">
<rect key="frame" x="25" y="20" width="271" height="117"/>
<textView autoresizesSubviews="NO" opaque="NO" clearsContextBeforeDrawing="NO" userInteractionEnabled="NO" contentMode="scaleAspectFit" ambiguous="YES" misplaced="YES" bounces="NO" scrollEnabled="NO" showsHorizontalScrollIndicator="NO" showsVerticalScrollIndicator="NO" delaysContentTouches="NO" canCancelContentTouches="NO" bouncesZoom="NO" editable="NO" translatesAutoresizingMaskIntoConstraints="NO" id="0Lx-zf-Lh8" userLabel="Kits textview">
<rect key="frame" x="0.0" y="0.0" width="240" height="128"/>
Update
This is what the scene looks like:
I also changed the frame settings in the storyboard and it made no difference. But I can see the new frame settings when I debug the code which is why I posted this question.
Update The code that is causing the problem is:
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;
textView.scrollEnabled = false
When I pause the code the fixedWidth = 300 (height 200) [I changed the size in the storyboard] but the newSize is 293 by 169. It has not kept the fixed width. This is why I started looking into the frame size.