0

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 enter image description here 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.

PatriciaW
  • 893
  • 1
  • 12
  • 30
  • I have another textview which behaves correctly (IMO) yet has the same settings (ambiguous and misplaced). Given that you think my constraints are incorrect how do I identify which one given that there is no indication of an error on the storyboard. – PatriciaW Sep 05 '15 at 16:42
  • The above comment refers to an extended discussion I had with Matt. He stated that my problem was caused by incorrect constraints. After some time I could not find any problems with constraints. He appears to have removed his comments as a result of this difference. – PatriciaW Sep 06 '15 at 17:45

1 Answers1

0

The problem resolved itself. I decided to add a height constraint to circumvent this problem. Then I posted another question outlining my problems with the textview width. After doing that I removed the height constraint and the width now is correct. I am not sure why it started to work because the new constraints are what I started off with. But perhaps they got corrupted somehow.

PatriciaW
  • 893
  • 1
  • 12
  • 30