Skip to content

Commit 26d74c9

Browse files
committed
Updated to Swift 2.0
1 parent a5f940a commit 26d74c9

File tree

1 file changed

+39
-33
lines changed

1 file changed

+39
-33
lines changed

Demo/Library/DatePickerDialog.swift

Lines changed: 39 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
1+
//
2+
// DatePicker.swift
3+
4+
import Foundation
15
import UIKit
26
import QuartzCore
37

8+
49
class DatePickerDialog: UIView {
510

611
/* Consts */
@@ -25,15 +30,16 @@ class DatePickerDialog: UIView {
2530
private var datePickerMode: UIDatePickerMode!
2631
private var callback: ((date: NSDate) -> Void)!
2732

33+
2834
/* Overrides */
29-
override init() {
35+
init() {
3036
super.init(frame: CGRectMake(0, 0, UIScreen.mainScreen().bounds.size.width, UIScreen.mainScreen().bounds.size.height))
3137

3238
NSNotificationCenter.defaultCenter().addObserver(self, selector: "deviceOrientationDidChange:", name: UIDeviceOrientationDidChangeNotification, object: nil)
3339
}
34-
40+
3541
required init(coder aDecoder: NSCoder) {
36-
super.init(coder: aDecoder)
42+
fatalError("init(coder:) has not been implemented")
3743
}
3844

3945
/* Handle device orientation changes */
@@ -42,11 +48,11 @@ class DatePickerDialog: UIView {
4248
}
4349

4450
/* Create the dialog view, and animate opening the dialog */
45-
func show(#title: String, datePickerMode: UIDatePickerMode = .DateAndTime, callback: ((date: NSDate) -> Void)) {
46-
show(title: title, doneButtonTitle: "Done", cancelButtonTitle: "Cancel", datePickerMode: datePickerMode, callback: callback)
51+
func show(title: String, datePickerMode: UIDatePickerMode = .DateAndTime, callback: ((date: NSDate) -> Void)) {
52+
show(title, doneButtonTitle: "Done", cancelButtonTitle: "Cancel", datePickerMode: datePickerMode, callback: callback)
4753
}
4854

49-
func show(#title: String, doneButtonTitle: String, cancelButtonTitle: String, defaultDate: NSDate = NSDate(), datePickerMode: UIDatePickerMode = .DateAndTime, callback: ((date: NSDate) -> Void)) {
55+
func show(title: String, doneButtonTitle: String, cancelButtonTitle: String, defaultDate: NSDate = NSDate(), datePickerMode: UIDatePickerMode = .DateAndTime, callback: ((date: NSDate) -> Void)) {
5056
self.title = title
5157
self.doneButtonTitle = doneButtonTitle
5258
self.cancelButtonTitle = cancelButtonTitle
@@ -71,27 +77,27 @@ class DatePickerDialog: UIView {
7177

7278
/* Attached to the top most window (make sure we are using the right orientation) */
7379
let interfaceOrientation = UIApplication.sharedApplication().statusBarOrientation
74-
80+
7581
switch(interfaceOrientation) {
76-
case UIInterfaceOrientation.LandscapeLeft:
77-
let t: Double = M_PI * 270 / 180
78-
self.transform = CGAffineTransformMakeRotation(CGFloat(t))
79-
break
82+
case UIInterfaceOrientation.LandscapeLeft:
83+
let t: Double = M_PI * 270 / 180
84+
self.transform = CGAffineTransformMakeRotation(CGFloat(t))
85+
break
8086

81-
case UIInterfaceOrientation.LandscapeRight:
82-
let t: Double = M_PI * 90 / 180
83-
self.transform = CGAffineTransformMakeRotation(CGFloat(t))
84-
break
85-
86-
case UIInterfaceOrientation.PortraitUpsideDown:
87-
let t: Double = M_PI * 180 / 180
88-
self.transform = CGAffineTransformMakeRotation(CGFloat(t))
89-
break
90-
91-
default:
92-
break
93-
}
87+
case UIInterfaceOrientation.LandscapeRight:
88+
let t: Double = M_PI * 90 / 180
89+
self.transform = CGAffineTransformMakeRotation(CGFloat(t))
90+
break
91+
92+
case UIInterfaceOrientation.PortraitUpsideDown:
93+
let t: Double = M_PI * 180 / 180
94+
self.transform = CGAffineTransformMakeRotation(CGFloat(t))
95+
break
9496

97+
default:
98+
break
99+
}
100+
95101
self.frame = CGRectMake(0, 0, self.frame.width, self.frame.size.height)
96102
UIApplication.sharedApplication().windows.first!.addSubview(self)
97103

@@ -113,7 +119,7 @@ class DatePickerDialog: UIView {
113119
private func close() {
114120
let currentTransform = self.dialogView.layer.transform
115121

116-
let startRotation = (self.valueForKeyPath("layer.transform.rotation.z") as? NSNumber)? as? Double ?? 0.0
122+
let startRotation = (self.valueForKeyPath("layer.transform.rotation.z") as? NSNumber) as? Double ?? 0.0
117123
let rotation = CATransform3DMakeRotation((CGFloat)(-startRotation + M_PI * 270 / 180), 0, 0, 0)
118124

119125
self.dialogView.layer.transform = CATransform3DConcat(rotation, CATransform3DMakeScale(1, 1, 1))
@@ -133,7 +139,7 @@ class DatePickerDialog: UIView {
133139
}
134140

135141
self.removeFromSuperview()
136-
}
142+
}
137143
}
138144

139145
/* Creates the container view here: create the dialog, then add the custom content and buttons */
@@ -142,8 +148,8 @@ class DatePickerDialog: UIView {
142148
let dialogSize = CGSizeMake(
143149
300,
144150
230
145-
+ kDatePickerDialogDefaultButtonHeight
146-
+ kDatePickerDialogDefaultButtonSpacerHeight)
151+
+ kDatePickerDialogDefaultButtonHeight
152+
+ kDatePickerDialogDefaultButtonSpacerHeight)
147153

148154
// For the black background
149155
self.frame = CGRectMake(0, 0, screenSize.width, screenSize.height)
@@ -155,8 +161,8 @@ class DatePickerDialog: UIView {
155161
let gradient: CAGradientLayer = CAGradientLayer(layer: self.layer)
156162
gradient.frame = dialogContainer.bounds
157163
gradient.colors = [UIColor(red: 218/255, green: 218/255, blue: 218/255, alpha: 1).CGColor,
158-
UIColor(red: 233/255, green: 233/255, blue: 233/255, alpha: 1).CGColor,
159-
UIColor(red: 218/255, green: 218/255, blue: 218/255, alpha: 1).CGColor]
164+
UIColor(red: 233/255, green: 233/255, blue: 233/255, alpha: 1).CGColor,
165+
UIColor(red: 218/255, green: 218/255, blue: 218/255, alpha: 1).CGColor]
160166

161167
let cornerRadius = kDatePickerDialogCornerRadius
162168
gradient.cornerRadius = cornerRadius
@@ -201,7 +207,7 @@ class DatePickerDialog: UIView {
201207
private func addButtonsToView(container: UIView) {
202208
let buttonWidth = container.bounds.size.width / 2
203209

204-
self.cancelButton = UIButton.buttonWithType(UIButtonType.Custom) as UIButton
210+
self.cancelButton = UIButton(type: UIButtonType.Custom) as UIButton
205211
self.cancelButton.frame = CGRectMake(
206212
0,
207213
container.bounds.size.height - kDatePickerDialogDefaultButtonHeight,
@@ -217,7 +223,7 @@ class DatePickerDialog: UIView {
217223
self.cancelButton.addTarget(self, action: "buttonTapped:", forControlEvents: UIControlEvents.TouchUpInside)
218224
container.addSubview(self.cancelButton)
219225

220-
self.doneButton = UIButton.buttonWithType(UIButtonType.Custom) as UIButton
226+
self.doneButton = UIButton(type: UIButtonType.Custom) as UIButton
221227
self.doneButton.frame = CGRectMake(
222228
buttonWidth,
223229
container.bounds.size.height - kDatePickerDialogDefaultButtonHeight,
@@ -260,4 +266,4 @@ class DatePickerDialog: UIView {
260266
return CGSizeMake(screenWidth, screenHeight)
261267
}
262268

263-
}
269+
}

0 commit comments

Comments
 (0)