2017-08-30 11 views
0

テーブルビューセルの下に正しい自動制約がないと思います。iOSテーブルビューのセルレイアウト自動制約、1行に4ラベル、2面に2行、2行

すべての単語はラベルです。つまり、1行に4つのラベルがあり、2つの行になります。

enter image description here

Iは右末尾に "20" を位置合わせしようとしたが、それは、 "名前" との重複を示しました。いくつかの提案をしようとした後に更新

enter image description here

+0

いくつかのコードを共有しますか? – antonio081014

+0

これはスタックビューの仕事ではないのですか? – matt

+0

@matt iOS 9+¯\\ _(ツ))/¯ – FreeNickname

答えて

1

はこれを試してみてください。また、横のラベルの1つをContent Compression Resistance Priorityに設定する必要があります。 700

enter image description here

enter image description here

+0

私は試しました。しかし、まだいくつかの問題があります、私はちょうど私の質問を更新しました、ありがとうございます。 – manhon

+0

どのような制約事項がありますか? http://imgur.com/a/vsl1n –

+0

自動レイアウトの問題ではなく、https://imgur.com/a/5xyrF – manhon

2

私はあなたが制約をpriorizeを必要とは思いません。

私はこの結果を得た:あなたは、テストプロジェクトを作成し、ストーリーボードファイルでこれを貼り付けることができ

<?xml version="1.0" encoding="UTF-8"?> 
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="12121" systemVersion="16G29" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES" initialViewController="pSd-1g-yzb"> 
    <device id="retina4_7" orientation="portrait"> 
     <adaptation id="fullscreen"/> 
    </device> 
    <dependencies> 
     <deployment identifier="iOS"/> 
     <plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="12089"/> 
     <capability name="Constraints to layout margins" minToolsVersion="6.0"/> 
     <capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/> 
    </dependencies> 
    <scenes> 
     <!--Second--> 
     <scene sceneID="N6t-4u-rEI"> 
      <objects> 
       <viewController id="pSd-1g-yzb" customClass="second" customModule="sdv" customModuleProvider="target" sceneMemberID="viewController"> 
        <layoutGuides> 
         <viewControllerLayoutGuide type="top" id="2V7-Hz-GBP"/> 
         <viewControllerLayoutGuide type="bottom" id="MEu-0g-Ng5"/> 
        </layoutGuides> 
        <view key="view" contentMode="scaleToFill" id="JAf-fN-bhN"> 
         <rect key="frame" x="0.0" y="0.0" width="375" height="667"/> 
         <autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/> 
         <subviews> 
          <tableView clipsSubviews="YES" contentMode="scaleToFill" fixedFrame="YES" alwaysBounceVertical="YES" dataMode="prototypes" style="plain" separatorStyle="default" rowHeight="106" sectionHeaderHeight="28" sectionFooterHeight="28" translatesAutoresizingMaskIntoConstraints="NO" id="RxB-gO-BaE"> 
           <rect key="frame" x="0.0" y="104" width="375" height="563"/> 
           <autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/> 
           <color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/> 
           <prototypes> 
            <tableViewCell clipsSubviews="YES" contentMode="scaleToFill" selectionStyle="default" indentationWidth="10" reuseIdentifier="Cell" rowHeight="106" id="ZS4-z5-fDX" customClass="cellTest" customModule="sdv" customModuleProvider="target"> 
             <rect key="frame" x="0.0" y="28" width="375" height="106"/> 
             <autoresizingMask key="autoresizingMask"/> 
             <tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" tableViewCell="ZS4-z5-fDX" id="Gzo-a3-xSX"> 
              <rect key="frame" x="0.0" y="0.0" width="375" height="105.5"/> 
              <autoresizingMask key="autoresizingMask"/> 
              <subviews> 
               <label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="name:" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="KZg-iQ-1yZ"> 
                <rect key="frame" x="8" y="15" width="47" height="21"/> 
                <constraints> 
                 <constraint firstAttribute="height" constant="21" id="QTh-E8-jrz"/> 
                 <constraint firstAttribute="width" constant="47" id="pXL-H9-1Pi"/> 
                </constraints> 
                <fontDescription key="fontDescription" type="system" pointSize="17"/> 
                <nil key="textColor"/> 
                <nil key="highlightedColor"/> 
               </label> 
               <label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="John" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="UDy-Br-8rJ"> 
                <rect key="frame" x="63" y="15" width="107" height="21"/> 
                <constraints> 
                 <constraint firstAttribute="height" constant="21" id="A4A-fg-T3O"/> 
                 <constraint firstAttribute="width" constant="107" id="clg-dt-kRd"/> 
                </constraints> 
                <fontDescription key="fontDescription" type="system" pointSize="17"/> 
                <nil key="textColor"/> 
                <nil key="highlightedColor"/> 
               </label> 
               <label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="City:" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="Ofl-yu-07n"> 
                <rect key="frame" x="8" y="44" width="35" height="21"/> 
                <constraints> 
                 <constraint firstAttribute="width" constant="35" id="byF-mE-EzO"/> 
                 <constraint firstAttribute="height" constant="21" id="pEY-1J-Juf"/> 
                </constraints> 
                <fontDescription key="fontDescription" type="system" pointSize="17"/> 
                <nil key="textColor"/> 
                <nil key="highlightedColor"/> 
               </label> 
               <label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="HK" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="uvr-jw-AgS"> 
                <rect key="frame" x="63" y="44" width="107" height="21"/> 
                <constraints> 
                 <constraint firstAttribute="height" constant="21" id="O8S-sI-SVg"/> 
                 <constraint firstAttribute="width" constant="107" id="OKt-4D-irY"/> 
                </constraints> 
                <fontDescription key="fontDescription" type="system" pointSize="17"/> 
                <nil key="textColor"/> 
                <nil key="highlightedColor"/> 
               </label> 
               <label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="20" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="OVW-yq-ra7"> 
                <rect key="frame" x="296" y="15" width="38" height="21"/> 
                <constraints> 
                 <constraint firstAttribute="width" constant="38" id="Tve-KR-3qg"/> 
                 <constraint firstAttribute="height" constant="21" id="XY5-8k-a8r"/> 
                </constraints> 
                <fontDescription key="fontDescription" type="system" pointSize="17"/> 
                <nil key="textColor"/> 
                <nil key="highlightedColor"/> 
               </label> 
               <label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Country:" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="sY6-0y-uY8"> 
                <rect key="frame" x="222" y="44" width="66" height="21"/> 
                <constraints> 
                 <constraint firstAttribute="width" constant="66" id="FQ4-Du-Kg5"/> 
                 <constraint firstAttribute="height" constant="21" id="f2H-DW-ZsP"/> 
                </constraints> 
                <fontDescription key="fontDescription" type="system" pointSize="17"/> 
                <nil key="textColor"/> 
                <nil key="highlightedColor"/> 
               </label> 
               <label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="HK" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="yGP-I1-NoG"> 
                <rect key="frame" x="296" y="44" width="38" height="21"/> 
                <constraints> 
                 <constraint firstAttribute="height" constant="21" id="pE3-ud-vJm"/> 
                 <constraint firstAttribute="width" constant="38" id="vLT-EO-jKF"/> 
                </constraints> 
                <fontDescription key="fontDescription" type="system" pointSize="17"/> 
                <nil key="textColor"/> 
                <nil key="highlightedColor"/> 
               </label> 
               <label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Age:" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="uPL-7i-yNc"> 
                <rect key="frame" x="253" y="15" width="35" height="21"/> 
                <constraints> 
                 <constraint firstAttribute="width" constant="35" id="mg8-e4-baN"/> 
                 <constraint firstAttribute="height" constant="21" id="oTV-cD-jy1"/> 
                </constraints> 
                <fontDescription key="fontDescription" type="system" pointSize="17"/> 
                <nil key="textColor"/> 
                <nil key="highlightedColor"/> 
               </label> 
              </subviews> 
              <constraints> 
               <constraint firstItem="KZg-iQ-1yZ" firstAttribute="top" secondItem="Gzo-a3-xSX" secondAttribute="topMargin" constant="7" id="30Z-xf-2jT"/> 
               <constraint firstItem="uvr-jw-AgS" firstAttribute="top" secondItem="UDy-Br-8rJ" secondAttribute="bottom" constant="8" id="3sf-vl-Ik6"/> 
               <constraint firstItem="Ofl-yu-07n" firstAttribute="leading" secondItem="Gzo-a3-xSX" secondAttribute="leadingMargin" id="Cq6-Rx-vkU"/> 
               <constraint firstAttribute="trailingMargin" secondItem="OVW-yq-ra7" secondAttribute="trailing" constant="33" id="DWV-l5-f18"/> 
               <constraint firstItem="Ofl-yu-07n" firstAttribute="top" secondItem="KZg-iQ-1yZ" secondAttribute="bottom" constant="8" id="KaQ-NN-tLo"/> 
               <constraint firstItem="yGP-I1-NoG" firstAttribute="leading" secondItem="sY6-0y-uY8" secondAttribute="trailing" constant="8" id="O2L-ng-7xA"/> 
               <constraint firstItem="UDy-Br-8rJ" firstAttribute="top" secondItem="Gzo-a3-xSX" secondAttribute="topMargin" constant="7" id="PVB-ck-Dlf"/> 
               <constraint firstAttribute="trailingMargin" secondItem="yGP-I1-NoG" secondAttribute="trailing" constant="33" id="RXc-0r-9rt"/> 
               <constraint firstItem="uvr-jw-AgS" firstAttribute="leading" secondItem="Ofl-yu-07n" secondAttribute="trailing" constant="20" id="ZQs-MN-PDV"/> 
               <constraint firstItem="KZg-iQ-1yZ" firstAttribute="leading" secondItem="Gzo-a3-xSX" secondAttribute="leadingMargin" id="ZZJ-gs-0Fs"/> 
               <constraint firstItem="yGP-I1-NoG" firstAttribute="top" secondItem="OVW-yq-ra7" secondAttribute="bottom" constant="8" id="f9a-58-K8F"/> 
               <constraint firstItem="sY6-0y-uY8" firstAttribute="top" secondItem="uPL-7i-yNc" secondAttribute="bottom" constant="8" id="hWN-Y2-3Ae"/> 
               <constraint firstItem="OVW-yq-ra7" firstAttribute="leading" secondItem="uPL-7i-yNc" secondAttribute="trailing" constant="8" id="mcM-m5-OXn"/> 
               <constraint firstItem="UDy-Br-8rJ" firstAttribute="leading" secondItem="KZg-iQ-1yZ" secondAttribute="trailing" constant="8" id="oOn-mC-oox"/> 
               <constraint firstItem="OVW-yq-ra7" firstAttribute="top" secondItem="Gzo-a3-xSX" secondAttribute="topMargin" constant="7" id="ycQ-u3-6lf"/> 
               <constraint firstItem="uPL-7i-yNc" firstAttribute="top" secondItem="Gzo-a3-xSX" secondAttribute="topMargin" constant="7" id="zbm-JK-27a"/> 
              </constraints> 
             </tableViewCellContentView> 
            </tableViewCell> 
           </prototypes> 
           <connections> 
            <outlet property="dataSource" destination="pSd-1g-yzb" id="tb8-8p-FL3"/> 
            <outlet property="delegate" destination="pSd-1g-yzb" id="plR-Bc-tN0"/> 
           </connections> 
          </tableView> 
         </subviews> 
         <color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/> 
        </view> 
        <connections> 
         <outlet property="tableView" destination="RxB-gO-BaE" id="kTb-PN-Tpd"/> 
        </connections> 
       </viewController> 
       <placeholder placeholderIdentifier="IBFirstResponder" id="skk-yw-pih" userLabel="First Responder" sceneMemberID="firstResponder"/> 
      </objects> 
      <point key="canvasLocation" x="493.60000000000002" y="74.212893553223395"/> 
     </scene> 
    </scenes> 
</document> 

:このストーリーボードを使用して

enter image description here

を。それで、あなたは私がどのように制約を守ったかを見ることができます。

enter image description here

は、あなたの携帯用のクラスを作成します:

class cellTest: UITableViewCell { 
    override func awakeFromNib() { 
     super.awakeFromNib() 
     // Initialization code 
    } 
} 

そして、あなたのデリゲートテーブルビューのために固定値を使用します。

class second: UIViewController, UITableViewDelegate, UITableViewDataSource { 
    @IBOutlet weak var tableView: UITableView! 

    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { 
     return 3 
    } 

    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { 
     let cellIdentifier: String = "Cell" 
     let cell : cellTest = self.tableView.dequeueReusableCell(withIdentifier: cellIdentifier, for: indexPath) as! cellTest 
     return cell 
    } 

    func numberOfSections(in tableView: UITableView) -> Int { 
     return 1 
    } 

} 
、ソースコードとしてそれを開くことを行うには

ストーリーボードに両方のクラスを設定するだけで、VCとセルのために、属性インスペクタ、テーブルビューのデータソースとdelegaでreuseIdentifierを設定しますあなたのVCに連絡して実行してください。

+0

ありがとうございます。しかし、私はipadにアプリをプレビューしたとき、それは余分なスペースです。例えばhttp://i63.tinypic.com/25jwo5v.png – manhon

+0

iPadに調整するには、特性にVaryを使用する必要があります。 – GIJOW

+0

https://stackoverflow.com/questions/39890055/what-is-vary-for-traits-in- xcode-8 – GIJOW

関連する問題