Skip to content

Commit 48a98ff

Browse files
committed
Add example of layout anchors
1 parent b27e63b commit 48a98ff

File tree

5 files changed

+237
-17
lines changed

5 files changed

+237
-17
lines changed

AutoLayout/AutoLayout.xcodeproj/project.pbxproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
objects = {
88

99
/* Begin PBXBuildFile section */
10+
5329F1161C79008300A35954 /* LayoutAnchorController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5329F1151C79008300A35954 /* LayoutAnchorController.swift */; };
1011
5362E7F81C53F1B200DAA88B /* CenterAlignViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5362E7F71C53F1B200DAA88B /* CenterAlignViewController.swift */; };
1112
53D6A5F11C53BF5200A81A14 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 53D6A5F01C53BF5200A81A14 /* AppDelegate.swift */; };
1213
53D6A5F31C53BF5200A81A14 /* MasterViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 53D6A5F21C53BF5200A81A14 /* MasterViewController.swift */; };
@@ -20,6 +21,7 @@
2021
/* End PBXBuildFile section */
2122

2223
/* Begin PBXFileReference section */
24+
5329F1151C79008300A35954 /* LayoutAnchorController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = LayoutAnchorController.swift; sourceTree = "<group>"; };
2325
5362E7F71C53F1B200DAA88B /* CenterAlignViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; indentWidth = 4; lastKnownFileType = sourcecode.swift; path = CenterAlignViewController.swift; sourceTree = "<group>"; tabWidth = 4; };
2426
53D6A5ED1C53BF5200A81A14 /* AutoLayout.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = AutoLayout.app; sourceTree = BUILT_PRODUCTS_DIR; };
2527
53D6A5F01C53BF5200A81A14 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
@@ -70,6 +72,7 @@
7072
53D6A5F01C53BF5200A81A14 /* AppDelegate.swift */,
7173
53D6A5F21C53BF5200A81A14 /* MasterViewController.swift */,
7274
5362E7F71C53F1B200DAA88B /* CenterAlignViewController.swift */,
75+
5329F1151C79008300A35954 /* LayoutAnchorController.swift */,
7376
53EDF4071C5D5C78009F91EA /* StackViewController.swift */,
7477
53D6A5F61C53BF5200A81A14 /* Main.storyboard */,
7578
53D6A5F91C53BF5200A81A14 /* Assets.xcassets */,
@@ -164,6 +167,7 @@
164167
53EDF40A1C5D64C1009F91EA /* UIStackView+addView.swift in Sources */,
165168
53D6A5F31C53BF5200A81A14 /* MasterViewController.swift in Sources */,
166169
53EDF4081C5D5C78009F91EA /* StackViewController.swift in Sources */,
170+
5329F1161C79008300A35954 /* LayoutAnchorController.swift in Sources */,
167171
53EDF40C1C5D6641009F91EA /* UIViewController+addView.swift in Sources */,
168172
5362E7F81C53F1B200DAA88B /* CenterAlignViewController.swift in Sources */,
169173
53D6A5F11C53BF5200A81A14 /* AppDelegate.swift in Sources */,

AutoLayout/AutoLayout/Base.lproj/LaunchScreen.storyboard

Lines changed: 44 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,67 @@
11
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
2-
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="9531" systemVersion="15D21" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" launchScreen="YES" useTraitCollections="YES" initialViewController="k06-eN-H4f">
2+
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="9532" systemVersion="15D21" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" launchScreen="YES" useTraitCollections="YES" initialViewController="k06-eN-H4f">
33
<dependencies>
44
<deployment identifier="iOS"/>
5-
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="9529"/>
5+
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="9530"/>
66
</dependencies>
77
<scenes>
8-
<!--AutoLayout-->
8+
<!--Auto Layout-->
99
<scene sceneID="pxc-vg-80V">
1010
<objects>
1111
<tableViewController id="FKO-EP-Sjd" sceneMemberID="viewController">
12-
<tableView key="view" clipsSubviews="YES" contentMode="scaleToFill" alwaysBounceVertical="YES" dataMode="static" style="plain" separatorStyle="default" rowHeight="44" sectionHeaderHeight="28" sectionFooterHeight="28" id="GSv-cf-fdx">
12+
<tableView key="view" clipsSubviews="YES" contentMode="scaleToFill" alwaysBounceVertical="YES" dataMode="static" style="plain" separatorStyle="default" rowHeight="64" sectionHeaderHeight="28" sectionFooterHeight="28" id="GSv-cf-fdx">
1313
<rect key="frame" x="0.0" y="0.0" width="600" height="600"/>
1414
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
1515
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
16+
<view key="tableFooterView" contentMode="scaleToFill" id="fBg-fk-aAi">
17+
<rect key="frame" x="0.0" y="320" width="600" height="0.0"/>
18+
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
19+
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
20+
</view>
1621
<sections>
1722
<tableViewSection id="WRV-bV-35R">
18-
<cells/>
23+
<cells>
24+
<tableViewCell clipsSubviews="YES" contentMode="scaleToFill" selectionStyle="blue" hidesAccessoryWhenEditing="NO" indentationLevel="1" indentationWidth="0.0" id="XAG-zN-Rpd">
25+
<rect key="frame" x="0.0" y="64" width="600" height="64"/>
26+
<autoresizingMask key="autoresizingMask"/>
27+
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" tableViewCell="XAG-zN-Rpd" id="nfT-ix-Src">
28+
<rect key="frame" x="0.0" y="0.0" width="600" height="63"/>
29+
<autoresizingMask key="autoresizingMask"/>
30+
</tableViewCellContentView>
31+
</tableViewCell>
32+
<tableViewCell clipsSubviews="YES" contentMode="scaleToFill" selectionStyle="blue" hidesAccessoryWhenEditing="NO" indentationLevel="1" indentationWidth="0.0" id="At2-9K-RCn">
33+
<rect key="frame" x="0.0" y="128" width="600" height="64"/>
34+
<autoresizingMask key="autoresizingMask"/>
35+
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" tableViewCell="At2-9K-RCn" id="6pf-uI-bgG">
36+
<rect key="frame" x="0.0" y="0.0" width="600" height="63"/>
37+
<autoresizingMask key="autoresizingMask"/>
38+
</tableViewCellContentView>
39+
</tableViewCell>
40+
<tableViewCell clipsSubviews="YES" contentMode="scaleToFill" selectionStyle="blue" hidesAccessoryWhenEditing="NO" indentationLevel="1" indentationWidth="0.0" id="yDA-a7-xeq">
41+
<rect key="frame" x="0.0" y="192" width="600" height="64"/>
42+
<autoresizingMask key="autoresizingMask"/>
43+
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" tableViewCell="yDA-a7-xeq" id="AGA-MD-ezE">
44+
<rect key="frame" x="0.0" y="0.0" width="600" height="63"/>
45+
<autoresizingMask key="autoresizingMask"/>
46+
</tableViewCellContentView>
47+
</tableViewCell>
48+
<tableViewCell clipsSubviews="YES" contentMode="scaleToFill" selectionStyle="blue" hidesAccessoryWhenEditing="NO" indentationLevel="1" indentationWidth="0.0" id="iGX-Lg-Isj">
49+
<rect key="frame" x="0.0" y="256" width="600" height="64"/>
50+
<autoresizingMask key="autoresizingMask"/>
51+
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" tableViewCell="iGX-Lg-Isj" id="0TZ-VR-aZH">
52+
<rect key="frame" x="0.0" y="0.0" width="600" height="63"/>
53+
<autoresizingMask key="autoresizingMask"/>
54+
</tableViewCellContentView>
55+
</tableViewCell>
56+
</cells>
1957
</tableViewSection>
2058
</sections>
2159
<connections>
2260
<outlet property="dataSource" destination="FKO-EP-Sjd" id="xcq-ga-l2M"/>
2361
<outlet property="delegate" destination="FKO-EP-Sjd" id="lbl-De-q5l"/>
2462
</connections>
2563
</tableView>
26-
<navigationItem key="navigationItem" title="AutoLayout" id="w7R-9T-cFr"/>
64+
<navigationItem key="navigationItem" title="Auto Layout" id="w7R-9T-cFr"/>
2765
</tableViewController>
2866
<placeholder placeholderIdentifier="IBFirstResponder" id="4R3-qS-jiV" userLabel="First Responder" sceneMemberID="firstResponder"/>
2967
</objects>

AutoLayout/AutoLayout/Base.lproj/Main.storyboard

Lines changed: 61 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
2-
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="9531" systemVersion="15D21" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" initialViewController="H1p-Uh-vWS">
2+
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="9532" systemVersion="15D21" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" initialViewController="H1p-Uh-vWS">
33
<dependencies>
44
<deployment identifier="iOS"/>
5-
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="9529"/>
5+
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="9530"/>
66
<capability name="Constraints with non-1.0 multipliers" minToolsVersion="5.1"/>
77
</dependencies>
88
<scenes>
@@ -108,6 +108,27 @@
108108
<segue destination="u9t-iT-tWP" kind="showDetail" identifier="SegueCAStack" id="bcA-eF-fRx"/>
109109
</connections>
110110
</tableViewCell>
111+
<tableViewCell contentMode="scaleToFill" selectionStyle="blue" accessoryType="disclosureIndicator" hidesAccessoryWhenEditing="NO" indentationLevel="1" indentationWidth="0.0" reuseIdentifier="Cell" textLabel="UuN-2A-3RZ" style="IBUITableViewCellStyleDefault" id="e40-Uv-dOT">
112+
<rect key="frame" x="0.0" y="256" width="600" height="64"/>
113+
<autoresizingMask key="autoresizingMask"/>
114+
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" tableViewCell="e40-Uv-dOT" id="2Hi-W4-PHD">
115+
<rect key="frame" x="0.0" y="0.0" width="567" height="63"/>
116+
<autoresizingMask key="autoresizingMask"/>
117+
<subviews>
118+
<label opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" text="Layout Anchors" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" id="UuN-2A-3RZ">
119+
<rect key="frame" x="15" y="0.0" width="550" height="63"/>
120+
<autoresizingMask key="autoresizingMask"/>
121+
<fontDescription key="fontDescription" style="UICTFontTextStyleBody"/>
122+
<color key="textColor" red="0.0" green="0.0" blue="0.0" alpha="1" colorSpace="calibratedRGB"/>
123+
<color key="highlightedColor" red="1" green="1" blue="1" alpha="1" colorSpace="calibratedRGB"/>
124+
</label>
125+
</subviews>
126+
</tableViewCellContentView>
127+
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
128+
<connections>
129+
<segue destination="2Sb-L4-qoK" kind="showDetail" identifier="SegueLayoutAnchors" id="KfT-jv-IcI"/>
130+
</connections>
131+
</tableViewCell>
111132
</cells>
112133
</tableViewSection>
113134
</sections>
@@ -120,7 +141,7 @@
120141
</tableViewController>
121142
<placeholder placeholderIdentifier="IBFirstResponder" id="Rux-fX-hf1" sceneMemberID="firstResponder"/>
122143
</objects>
123-
<point key="canvasLocation" x="709" y="-630"/>
144+
<point key="canvasLocation" x="713" y="-630"/>
124145
</scene>
125146
<!--Navigation Controller-->
126147
<scene sceneID="Io5-wz-o8f">
@@ -240,6 +261,25 @@
240261
</objects>
241262
<point key="canvasLocation" x="1437" y="233"/>
242263
</scene>
264+
<!--Layout Anchors-->
265+
<scene sceneID="rbu-H9-fzS">
266+
<objects>
267+
<viewController id="sMC-zO-3gm" customClass="LayoutAnchorController" customModule="AutoLayout" customModuleProvider="target" sceneMemberID="viewController">
268+
<layoutGuides>
269+
<viewControllerLayoutGuide type="top" id="CLc-kz-sQa"/>
270+
<viewControllerLayoutGuide type="bottom" id="2Sw-jc-N0g"/>
271+
</layoutGuides>
272+
<view key="view" contentMode="scaleToFill" id="8oV-Gh-G1N">
273+
<rect key="frame" x="0.0" y="0.0" width="600" height="600"/>
274+
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
275+
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
276+
</view>
277+
<navigationItem key="navigationItem" title="Layout Anchors" id="XlE-eb-7cw"/>
278+
</viewController>
279+
<placeholder placeholderIdentifier="IBFirstResponder" id="aiI-fK-XmS" userLabel="First Responder" sceneMemberID="firstResponder"/>
280+
</objects>
281+
<point key="canvasLocation" x="2185" y="914"/>
282+
</scene>
243283
<!--Navigation Controller-->
244284
<scene sceneID="l7g-3J-iXA">
245285
<objects>
@@ -256,6 +296,24 @@
256296
</objects>
257297
<point key="canvasLocation" x="1437" y="-447"/>
258298
</scene>
299+
<!--Navigation Controller-->
300+
<scene sceneID="zlg-ch-kBA">
301+
<objects>
302+
<navigationController automaticallyAdjustsScrollViewInsets="NO" id="2Sb-L4-qoK" sceneMemberID="viewController">
303+
<toolbarItems/>
304+
<navigationBar key="navigationBar" contentMode="scaleToFill" id="84p-GG-6Zx">
305+
<rect key="frame" x="0.0" y="0.0" width="320" height="44"/>
306+
<autoresizingMask key="autoresizingMask"/>
307+
</navigationBar>
308+
<nil name="viewControllers"/>
309+
<connections>
310+
<segue destination="sMC-zO-3gm" kind="relationship" relationship="rootViewController" id="xs5-wv-20u"/>
311+
</connections>
312+
</navigationController>
313+
<placeholder placeholderIdentifier="IBFirstResponder" id="acD-78-6VB" userLabel="First Responder" sceneMemberID="firstResponder"/>
314+
</objects>
315+
<point key="canvasLocation" x="1444" y="908"/>
316+
</scene>
259317
</scenes>
260318
<resources>
261319
<image name="Heart" width="100" height="100"/>

0 commit comments

Comments
 (0)