on master help sign in
Layout subviews
d007035Gunay Mert Karadogan
GMStepper/GMStepper/Base.lproj/Main.storyboard+16
@@ -2,6 +2,7 @@
2<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">
2<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">
3 <dependencies>
3 <dependencies>
4 <plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="8101.16"/>
4 <plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="8101.16"/>
5+ <capability name="Constraints to layout margins" minToolsVersion="6.0"/>
5 </dependencies>
6 </dependencies>
6 <scenes>
7 <scenes>
7 <!--View Controller-->
8 <!--View Controller-->
@@ -15,11 +16,26 @@
15 <view key="view" contentMode="scaleToFill" id="8bC-Xf-vdC">
16 <view key="view" contentMode="scaleToFill" id="8bC-Xf-vdC">
16 <rect key="frame" x="0.0" y="0.0" width="600" height="600"/>
17 <rect key="frame" x="0.0" y="0.0" width="600" height="600"/>
17 <autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
18 <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>
18 <color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="calibratedWhite"/>
29 <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>
19 </view>
34 </view>
20 </viewController>
35 </viewController>
21 <placeholder placeholderIdentifier="IBFirstResponder" id="dkx-z0-nzr" sceneMemberID="firstResponder"/>
36 <placeholder placeholderIdentifier="IBFirstResponder" id="dkx-z0-nzr" sceneMemberID="firstResponder"/>
22 </objects>
37 </objects>
38+ <point key="canvasLocation" x="340" y="387"/>
23 </scene>
39 </scene>
24 </scenes>
40 </scenes>
25</document>
41</document>
GMStepper/GMStepper/GMStepper.swift+23
@@ -25,8 +25,31 @@ class GMStepper: UIView {
25 leftButton.addTarget(self, action: "leftButtonTapped:", forControlEvents: .TouchDown)
25 leftButton.addTarget(self, action: "leftButtonTapped:", forControlEvents: .TouchDown)
26 rightButton.addTarget(self, action: "rightButtonTapped:", forControlEvents: .TouchDown)
26 rightButton.addTarget(self, action: "rightButtonTapped:", forControlEvents: .TouchDown)
27
27
28+ label.textAlignment = .Center
29+
28 addSubview(leftButton)
30 addSubview(leftButton)
29 addSubview(rightButton)
31 addSubview(rightButton)
30 addSubview(label)
32 addSubview(label)
31 }
33 }
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+ }
32}
55}