0
votes

I just find a strange behavior in Interface Builder with Storyboard.

If I set a UIView with:
• Equal Width to the superview, multiplier 1
• Center horizontally to the superview, multiplier x

Then I would expect the width always as the same value but no, I have 2 behaviors:
• x >= 1 => width is as expected same value as the superview
• x < 1 => width is 0.5 pixel larger than the superview

Do I miss something?

Here is an extract of the storyboard with 2 views for both case

  <subviews>
      <view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="CtB-in-rfQ">
          <rect key="frame" x="0.0" y="20" width="375" height="267"/>
          <color key="backgroundColor" white="0.66666666666666663" alpha="1" colorSpace="calibratedWhite"/>
      </view>
      <view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="N87-No-JIr">
          <rect key="frame" x="-94" y="400" width="375.5" height="267"/>
          <color key="backgroundColor" white="0.33333333333333331" alpha="1" colorSpace="calibratedWhite"/>
      </view>
  </subviews>

EDIT: enter image description here As you can see, dark gray view has width equal to superview + center X equal to 0.5 x center X of superview.
BUT
The width of dark gray view is 375.5 pixel. The x position should be -93.75 pixel, rounded 0.25 pixel to the left. So I guess to still have view centered to 187.5 pixel, Interface builder add another 0.25 pixel to the right that end of 0.5 pixel larger.

What I would expect is the frame is more important and didn't change when I change multiplier of center X constraint. (that is for me no relation with the width).

1

1 Answers

0
votes

By seeing the constraints I can see that they are ambiguous. The subview still requires X and Y constraints to display properly.

What exactly you are trying to achieve? let me know. Please check the screenshots attached. let me know what exactly you are trying to achieve.

Correct one : 1. Make the Width 0.5 or whatever you desired 2. Make it Center Horizontal with Safe View 3. Set respective Y Constraints.

enter image description here