Alan2
Alan2

Reputation: 24572

How can I add a vertical space between an image and a label in an iOS view controller

Here is the XAML that I have for my storyboard:

<stackView opaque="NO" contentMode="scaleToFill" axis="vertical" distribution="equalCentering" alignment="center" translatesAutoresizingMaskIntoConstraints="NO" id="Zbh-CC-wDS" misplaced="YES">
  <rect key="frame" x="107" y="294" width="200" height="188"/>
  <subviews>
    <imageView clipsSubviews="YES" userInteractionEnabled="NO" contentMode="scaleAspectFit" horizontalHuggingPriority="251" verticalHuggingPriority="251" image="splash_image.png" translatesAutoresizingMaskIntoConstraints="NO" id="znN-uk-H0B" misplaced="YES">
      <rect key="frame" x="36" y="0.0" width="128" height="80"/>
      <constraints>
        <constraint firstAttribute="height" constant="80" id="A2X-j1-ymP"/>
      </constraints>
    </imageView>
    <view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="BWy-bZ-hd4">
      <rect key="frame" x="0.0" y="80" width="200" height="50"/>
        <color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
    </view>
    <label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" 
      text="ABC" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" 
      id="EcF-nC-k2o" colorLabel="IBBuiltInLabel-Gray">
    <rect key="frame" x="36" y="152" width="128" height="36"/>
      <fontDescription key="fontDescription" type="system" pointSize="30"/>
      <color key="textColor" white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
      <nil key="highlightedColor"/>
    </label>
  </subviews>
</stackView>

The designer has created a:

View Controller
   Safe Area
      Stack View
         spash_image.png
         View
         XXX

Is there a way that instead of using a View as a means to provide distance between the image and the label, that I could use something else. Perhaps add a vertical constraint somehow.

I would appreciate any suggestions

Upvotes: 0

Views: 391

Answers (1)

Keshu R.
Keshu R.

Reputation: 5225

Select the StackView and you will see Spacing option in Attribute Inspector. Set it to 10-20 or any value you want.

enter image description here

Upvotes: 5

Related Questions