on master help sign in
Layout subviews
commitd0070352cc61b1fa58aa856f7bc043ef115e3ef1 authorGunay Mert Karadogan <mertkaradogan@gmail.com> dateWed 1 Jul 2015, 13:17 (11 years ago) parenta000861
2 files changed+39
GMStepper/GMStepper/Base.lproj/Main.storyboard+16 GMStepper/GMStepper/GMStepper.swift+23
GMStepper/GMStepper/Base.lproj/Main.storyboard+16
@@ -2,6 +2,7 @@
22<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="8121.20" systemVersion="14D136" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" initialViewController="BYZ-38-t0r">
33 <dependencies>
44 <plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="8101.16"/>
5+ <capability name="Constraints to layout margins" minToolsVersion="6.0"/>
56 </dependencies>
67 <scenes>
78 <!--View Controller-->
@@ -15,11 +16,26 @@
1516 <view key="view" contentMode="scaleToFill" id="8bC-Xf-vdC">
1617 <rect key="frame" x="0.0" y="0.0" width="600" height="600"/>
1718 <autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
19+ <subviews>
20+ <view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="myb-yU-Jdq" customClass="GMStepper" customModule="GMStepper" customModuleProvider="target">
21+ <rect key="frame" x="20" y="20" width="284" height="44"/>
22+ <color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
23+ <constraints>
24+ <constraint firstAttribute="width" constant="284" id="RLe-7a-S9I"/>
25+ <constraint firstAttribute="height" constant="44" id="bMh-qb-O1H"/>
26+ </constraints>
27+ </view>
28+ </subviews>
1829 <color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="calibratedWhite"/>
30+ <constraints>
31+ <constraint firstAttribute="leadingMargin" secondItem="myb-yU-Jdq" secondAttribute="leading" id="NuJ-b9-mHR"/>
32+ <constraint firstItem="myb-yU-Jdq" firstAttribute="top" secondItem="y3c-jy-aDJ" secondAttribute="bottom" id="xo4-e0-e0r"/>
33+ </constraints>
1934 </view>
2035 </viewController>
2136 <placeholder placeholderIdentifier="IBFirstResponder" id="dkx-z0-nzr" sceneMemberID="firstResponder"/>
2237 </objects>
38+ <point key="canvasLocation" x="340" y="387"/>
2339 </scene>
2440 </scenes>
2541</document>
GMStepper/GMStepper/GMStepper.swift+23
@@ -25,8 +25,31 @@ class GMStepper: UIView {
2525 leftButton.addTarget(self, action: "leftButtonTapped:", forControlEvents: .TouchDown)
2626 rightButton.addTarget(self, action: "rightButtonTapped:", forControlEvents: .TouchDown)
2727
28+ label.textAlignment = .Center
29+
2830 addSubview(leftButton)
2931 addSubview(rightButton)
3032 addSubview(label)
3133 }
34+
35+ override func layoutSubviews() {
36+ let buttonSize = Int(frame.size.height)
37+ let labelWidth = Int(frame.size.width) - 2 * buttonSize
38+
39+ let leftButtonFrame = CGRect(x: 0, y: 0, width: buttonSize, height: buttonSize)
40+ let labelFrame = CGRect(x: buttonSize, y: 0, width: labelWidth, height: buttonSize)
41+ let rightButtonFrame = CGRect(x: buttonSize + labelWidth, y: 0, width: buttonSize, height: buttonSize)
42+
43+ leftButton.frame = leftButtonFrame
44+ label.frame = labelFrame
45+ rightButton.frame = rightButtonFrame
46+ }
47+
48+ func leftButtonTapped(button: UIButton) {
49+
50+ }
51+
52+ func rightButtonTapped(button: UIButton) {
53+
54+ }
3255}