on master help sign in
Subclass UIControl instead of UIView
4ac97ccGunay Mert Karadogan
GMStepper/GMStepper/Base.lproj/Main.storyboard+3−8
@@ -25,14 +25,6 @@
25 <constraint firstAttribute="height" constant="44" id="bMh-qb-O1H"/>
25 <constraint firstAttribute="height" constant="44" id="bMh-qb-O1H"/>
26 </constraints>
26 </constraints>
27 </view>
27 </view>
28− <view contentMode="scaleToFill" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="LHM-6l-lrt" customClass="GMStepper" customModule="GMStepper" customModuleProvider="target">
29− <rect key="frame" x="20" y="323" width="391" height="209"/>
30− <color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
31− </view>
32− <view contentMode="scaleToFill" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="rA3-ct-Qsh" customClass="GMStepper" customModule="GMStepper" customModuleProvider="target">
33− <rect key="frame" x="20" y="129" width="240" height="128"/>
34− <color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
35− </view>
36 </subviews>
28 </subviews>
37 <color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="calibratedWhite"/>
29 <color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="calibratedWhite"/>
38 <constraints>
30 <constraints>
@@ -40,6 +32,9 @@
40 <constraint firstItem="myb-yU-Jdq" firstAttribute="top" secondItem="y3c-jy-aDJ" secondAttribute="bottom" id="xo4-e0-e0r"/>
32 <constraint firstItem="myb-yU-Jdq" firstAttribute="top" secondItem="y3c-jy-aDJ" secondAttribute="bottom" id="xo4-e0-e0r"/>
41 </constraints>
33 </constraints>
42 </view>
34 </view>
35+ <connections>
36+ <outlet property="stepper" destination="myb-yU-Jdq" id="B3e-dV-hSv"/>
37+ </connections>
43 </viewController>
38 </viewController>
44 <placeholder placeholderIdentifier="IBFirstResponder" id="dkx-z0-nzr" sceneMemberID="firstResponder"/>
39 <placeholder placeholderIdentifier="IBFirstResponder" id="dkx-z0-nzr" sceneMemberID="firstResponder"/>
45 </objects>
40 </objects>
GMStepper/GMStepper/GMStepper.swift+5−1
@@ -8,11 +8,15 @@
8
8
9import UIKit
9import UIKit
10
10
11−public class GMStepper: UIView {
11+public class GMStepper: UIControl {
12 public var value = 0 {
12 public var value = 0 {
13 didSet {
13 didSet {
14 value = min(maximumValue, max(minimumValue, value))
14 value = min(maximumValue, max(minimumValue, value))
15 label.text = String(value)
15 label.text = String(value)
16+
17+ if oldValue != value {
18+ sendActionsForControlEvents(.ValueChanged)
19+ }
16 }
20 }
17 }
21 }
18
22
GMStepper/GMStepper/ViewController.swift+6−7
@@ -10,16 +10,15 @@ import UIKit
10
10
11class ViewController: UIViewController {
11class ViewController: UIViewController {
12
12
13+ @IBOutlet weak var stepper: GMStepper!
14+
13 override func viewDidLoad() {
15 override func viewDidLoad() {
14 super.viewDidLoad()
16 super.viewDidLoad()
15− // Do any additional setup after loading the view, typically from a nib.
17+ stepper.addTarget(self, action: "stepperValueChanged:", forControlEvents: .ValueChanged)
16 }
18 }
17−
19+
18− override func didReceiveMemoryWarning() {
20+ func stepperValueChanged(stepper: GMStepper) {
19− super.didReceiveMemoryWarning()
21+ print(stepper.value)
20− // Dispose of any resources that can be recreated.
21 }
22 }
22−
23−
24}
23}
25
24