on master help sign in
Subclass UIControl instead of UIView
commit4ac97cc0509b36d0a878ff9ff56bff57905efc54 authorGunay Mert Karadogan <mertkaradogan@gmail.com> dateWed 1 Jul 2015, 17:46 (11 years ago) parent3a23690
3 files changed+14−16
GMStepper/GMStepper/Base.lproj/Main.storyboard+3−8 GMStepper/GMStepper/GMStepper.swift+5−1 GMStepper/GMStepper/ViewController.swift+6−7
GMStepper/GMStepper/Base.lproj/Main.storyboard+3−8
@@ -25,14 +25,6 @@
2525 <constraint firstAttribute="height" constant="44" id="bMh-qb-O1H"/>
2626 </constraints>
2727 </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>
3628 </subviews>
3729 <color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="calibratedWhite"/>
3830 <constraints>
@@ -40,6 +32,9 @@
4032 <constraint firstItem="myb-yU-Jdq" firstAttribute="top" secondItem="y3c-jy-aDJ" secondAttribute="bottom" id="xo4-e0-e0r"/>
4133 </constraints>
4234 </view>
35+ <connections>
36+ <outlet property="stepper" destination="myb-yU-Jdq" id="B3e-dV-hSv"/>
37+ </connections>
4338 </viewController>
4439 <placeholder placeholderIdentifier="IBFirstResponder" id="dkx-z0-nzr" sceneMemberID="firstResponder"/>
4540 </objects>
GMStepper/GMStepper/GMStepper.swift+5−1
@@ -8,11 +8,15 @@
88
99import UIKit
1010
11−public class GMStepper: UIView {
11+public class GMStepper: UIControl {
1212 public var value = 0 {
1313 didSet {
1414 value = min(maximumValue, max(minimumValue, value))
1515 label.text = String(value)
16+
17+ if oldValue != value {
18+ sendActionsForControlEvents(.ValueChanged)
19+ }
1620 }
1721 }
1822
GMStepper/GMStepper/ViewController.swift+6−7
@@ -10,16 +10,15 @@ import UIKit
1010
1111class ViewController: UIViewController {
1212
13+ @IBOutlet weak var stepper: GMStepper!
14+
1315 override func viewDidLoad() {
1416 super.viewDidLoad()
15− // Do any additional setup after loading the view, typically from a nib.
17+ stepper.addTarget(self, action: "stepperValueChanged:", forControlEvents: .ValueChanged)
1618 }
17−
18− override func didReceiveMemoryWarning() {
19− super.didReceiveMemoryWarning()
20− // Dispose of any resources that can be recreated.
19+
20+ func stepperValueChanged(stepper: GMStepper) {
21+ print(stepper.value)
2122 }
22−
23−
2423}
2524