uistoryboard 中水平方向的 stackview 内的控件右对齐

问题描述 投票:0回答:1

我有一个垂直方向的StackView(卡片视图),对齐和分布都是“填充”。

在里面我还有一些水平方向的 StackView 和一些其他控件。其中,最后一个具有水平方向的 StackView,Alignment = Top 和 Distribution = Fill,有两个按钮“保存”和“取消”

最后一个堆栈视图的 XML:

<stackView opaque="NO" contentMode="right" alignment="top" spacing="15" translatesAutoresizingMaskIntoConstraints="NO" id="qk0-Aa-LVy">
<rect key="frame" x="0.0" y="301" width="414" height="51"/>
<subviews>
    <button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="system" lineBreakMode="wordWrap" translatesAutoresizingMaskIntoConstraints="NO" id="TzA-jj-KRx">
        <rect key="frame" x="0.0" y="0.0" width="199.66666666666666" height="31"/>
        <inset key="contentEdgeInsets" minX="10" minY="10" maxX="10" maxY="10"/>
        <state key="normal" title="Button"/>
        <buttonConfiguration key="configuration" style="plain" title="Save" buttonSize="medium"/>
    </button>
    <button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="system" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="xHU-No-XcV">
        <rect key="frame" x="214.66666666666663" y="0.0" width="199.33333333333337" height="31"/>
        <state key="normal" title="Button"/>
        <buttonConfiguration key="configuration" style="plain" title="Cancel"/>
    </button>
</subviews>
<constraints>
    <constraint firstAttribute="bottomMargin" secondItem="TzA-jj-KRx" secondAttribute="bottom" constant="20" id="d5Z-DX-Keg"/>
</constraints>

我希望两个按钮右对齐,但我不知道如何实现。我使用 Xamarin.iOS。

请注意,可能存在一些不需要的约束和其他代码,因为这是我的第一个学习项目。请让我知道需要更多 xml 行。预先感谢。

uiview xamarin.ios storyboard uistackview
1个回答
0
投票

如果想让两个按钮右对齐,可以创建一个父UIView,然后在其中分别添加两个子UIView,使两个按钮右对齐。我做了一个小demo,大家可以参考一下:

<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="21701" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES">
    <device id="retina6_12" orientation="portrait" appearance="light"/>
    <dependencies>
        <deployment identifier="iOS"/>
        <plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="21679"/>
        <capability name="System colors in document resources" minToolsVersion="11.0"/>
        <capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
    </dependencies>
    <scenes>
        <!--View Controller-->
        <scene sceneID="spr-Nj-etT">
            <objects>
                <viewController id="Guk-rI-Gf8" customClass="ViewController" sceneMemberID="viewController">
                    <layoutGuides>
                        <viewControllerLayoutGuide type="top" id="KYh-z1-5xj"/>
                        <viewControllerLayoutGuide type="bottom" id="zwR-AE-XVK"/>
                    </layoutGuides>
                    <view key="view" contentMode="scaleToFill" id="P0e-PR-rP8">
                        <rect key="frame" x="0.0" y="0.0" width="393" height="852"/>
                        <autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
                        <subviews>
                            <view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="jIo-mB-Hep" userLabel="ViewSupper">
                                <rect key="frame" x="3.6666666666666572" y="366.66666666666669" width="386" height="119"/>
                                <subviews>
                                    <view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="hou-Hd-LV5" userLabel="ViewFirst" colorLabel="IBBuiltInLabel-Green">
                                        <rect key="frame" x="0.0" y="0.0" width="190.33333333333334" height="119"/>
                                        <subviews>
                                            <button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="system" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="wm0-Je-5sg">
                                                <rect key="frame" x="115.33333333333331" y="37.333333333333314" width="75" height="44"/>
                                                <constraints>
                                                    <constraint firstAttribute="height" constant="44" id="MaV-yf-fwZ"/>
                                                </constraints>
                                                <state key="normal" title="Button"/>
                                                <buttonConfiguration key="configuration" style="plain" title="Button"/>
                                            </button>
                                        </subviews>
                                        <color key="backgroundColor" systemColor="systemGreenColor"/>
                                        <constraints>
                                            <constraint firstItem="wm0-Je-5sg" firstAttribute="centerY" secondItem="hou-Hd-LV5" secondAttribute="centerY" id="RDm-XQ-tL2"/>
                                            <constraint firstAttribute="trailing" secondItem="wm0-Je-5sg" secondAttribute="trailing" id="rNO-sv-6Lp"/>
                                        </constraints>
                                    </view>
                                    <view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="22h-St-obH" userLabel="ViewSecond">
                                        <rect key="frame" x="190.33333333333337" y="0.0" width="195.66666666666663" height="119"/>
                                        <subviews>
                                            <button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="system" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="egB-Xx-Pte">
                                                <rect key="frame" x="120.66666666666669" y="37.333333333333314" width="75" height="44"/>
                                                <constraints>
                                                    <constraint firstAttribute="height" constant="44" id="FKH-MZ-qtN"/>
                                                </constraints>
                                                <state key="normal" title="Button"/>
                                                <buttonConfiguration key="configuration" style="plain" title="Button"/>
                                            </button>
                                        </subviews>
                                        <color key="backgroundColor" systemColor="systemPinkColor"/>
                                        <constraints>
                                            <constraint firstAttribute="trailing" secondItem="egB-Xx-Pte" secondAttribute="trailing" id="joD-7q-Baa"/>
                                            <constraint firstItem="egB-Xx-Pte" firstAttribute="centerY" secondItem="22h-St-obH" secondAttribute="centerY" id="tAZ-iF-4o0"/>
                                        </constraints>
                                    </view>
                                </subviews>
                                <color key="backgroundColor" systemColor="systemOrangeColor"/>
                                <constraints>
                                    <constraint firstItem="22h-St-obH" firstAttribute="top" secondItem="jIo-mB-Hep" secondAttribute="top" id="2E4-pq-d40"/>
                                    <constraint firstItem="hou-Hd-LV5" firstAttribute="top" secondItem="jIo-mB-Hep" secondAttribute="top" id="2I4-Ck-kQo"/>
                                    <constraint firstItem="hou-Hd-LV5" firstAttribute="centerY" secondItem="jIo-mB-Hep" secondAttribute="centerY" id="9s3-uN-g73"/>
                                    <constraint firstItem="22h-St-obH" firstAttribute="leading" secondItem="hou-Hd-LV5" secondAttribute="trailing" id="CzH-c3-dvZ"/>
                                    <constraint firstAttribute="trailing" secondItem="22h-St-obH" secondAttribute="trailing" id="Hpj-cG-73v"/>
                                    <constraint firstItem="22h-St-obH" firstAttribute="leading" secondItem="hou-Hd-LV5" secondAttribute="trailing" id="It0-q1-ijW"/>
                                    <constraint firstItem="hou-Hd-LV5" firstAttribute="width" secondItem="jIo-mB-Hep" secondAttribute="width" multiplier="0.492228" constant="0.5" id="O2s-bs-iXt"/>
                                    <constraint firstAttribute="height" constant="119" id="dLz-AL-dDk"/>
                                    <constraint firstAttribute="width" constant="386" id="e2p-io-yC7"/>
                                    <constraint firstItem="hou-Hd-LV5" firstAttribute="leading" secondItem="jIo-mB-Hep" secondAttribute="leading" id="f4B-CY-DTJ"/>
                                    <constraint firstAttribute="bottom" secondItem="hou-Hd-LV5" secondAttribute="bottom" id="hy9-jf-Coc"/>
                                    <constraint firstAttribute="bottom" secondItem="22h-St-obH" secondAttribute="bottom" id="syj-GC-MaV"/>
                                </constraints>
                            </view>
                        </subviews>
                        <color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
                        <constraints>
                            <constraint firstItem="jIo-mB-Hep" firstAttribute="centerX" secondItem="P0e-PR-rP8" secondAttribute="centerX" id="Hij-uC-gfu"/>
                            <constraint firstItem="jIo-mB-Hep" firstAttribute="centerY" secondItem="P0e-PR-rP8" secondAttribute="centerY" id="oLW-Cv-X0i"/>
                        </constraints>
                    </view>
                </viewController>
                <placeholder placeholderIdentifier="IBFirstResponder" id="XcU-Kh-a1t" sceneMemberID="firstResponder"/>
            </objects>
            <point key="canvasLocation" x="1052.6717557251909" y="14.084507042253522"/>
        </scene>
    </scenes>
    <resources>
        <systemColor name="systemGreenColor">
            <color red="0.20392156862745098" green="0.7803921568627451" blue="0.34901960784313724" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
        </systemColor>
        <systemColor name="systemOrangeColor">
            <color red="1" green="0.58431372549019611" blue="0.0" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
        </systemColor>
        <systemColor name="systemPinkColor">
            <color red="1" green="0.17647058823529413" blue="0.33333333333333331" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
        </systemColor>
    </resources>
</document>

输出:

© www.soinside.com 2019 - 2024. All rights reserved.