From f138d7b5059ffd49b310f5b0058e1fa720345da4 Mon Sep 17 00:00:00 2001 From: nartex Date: Tue, 24 Nov 2015 09:36:46 +0100 Subject: [PATCH 01/11] Updated to work in Swift 2.0 Updated to work in Swift 2.0 and made pretty much everything public in order to make it working correctly as a lib --- DOAlertController/DOAlertController.swift | 143 +++++++++++----------- 1 file changed, 71 insertions(+), 72 deletions(-) diff --git a/DOAlertController/DOAlertController.swift b/DOAlertController/DOAlertController.swift index b322ec8..9e98853 100644 --- a/DOAlertController/DOAlertController.swift +++ b/DOAlertController/DOAlertController.swift @@ -14,24 +14,24 @@ import UIKit let DOAlertActionEnabledDidChangeNotification = "DOAlertActionEnabledDidChangeNotification" -enum DOAlertActionStyle : Int { +public enum DOAlertActionStyle : Int { case Default case Cancel case Destructive } -enum DOAlertControllerStyle : Int { +public enum DOAlertControllerStyle : Int { case ActionSheet case Alert } // MARK: DOAlertAction Class -class DOAlertAction : NSObject, NSCopying { - var title: String - var style: DOAlertActionStyle - var handler: ((DOAlertAction!) -> Void)! - var enabled: Bool { +public class DOAlertAction : NSObject, NSCopying { + public var title: String + public var style: DOAlertActionStyle + public var handler: ((DOAlertAction!) -> Void)! + public var enabled: Bool { didSet { if (oldValue != enabled) { NSNotificationCenter.defaultCenter().postNotificationName(DOAlertActionEnabledDidChangeNotification, object: nil) @@ -39,15 +39,15 @@ class DOAlertAction : NSObject, NSCopying { } } - required init(title: String, style: DOAlertActionStyle, handler: ((DOAlertAction!) -> Void)!) { + public required init(title: String, style: DOAlertActionStyle, handler: ((DOAlertAction!) -> Void)!) { self.title = title self.style = style self.handler = handler self.enabled = true } - func copyWithZone(zone: NSZone) -> AnyObject { - let copy = self.dynamicType(title: title, style: style, handler: handler) + public func copyWithZone(zone: NSZone) -> AnyObject { + let copy = self.dynamicType.init(title: title, style: style, handler: handler) copy.enabled = self.enabled return copy } @@ -55,15 +55,15 @@ class DOAlertAction : NSObject, NSCopying { // MARK: DOAlertAnimation Class -class DOAlertAnimation : NSObject, UIViewControllerAnimatedTransitioning { +public class DOAlertAnimation : NSObject, UIViewControllerAnimatedTransitioning { - let isPresenting: Bool + public let isPresenting: Bool - init(isPresenting: Bool) { + public init(isPresenting: Bool) { self.isPresenting = isPresenting } - func transitionDuration(transitionContext: UIViewControllerContextTransitioning) -> NSTimeInterval { + public func transitionDuration(transitionContext: UIViewControllerContextTransitioning?) -> NSTimeInterval { if (isPresenting) { return 0.45 } else { @@ -71,7 +71,7 @@ class DOAlertAnimation : NSObject, UIViewControllerAnimatedTransitioning { } } - func animateTransition(transitionContext: UIViewControllerContextTransitioning) { + public func animateTransition(transitionContext: UIViewControllerContextTransitioning) { if (isPresenting) { self.presentAnimateTransition(transitionContext) } else { @@ -79,10 +79,10 @@ class DOAlertAnimation : NSObject, UIViewControllerAnimatedTransitioning { } } - func presentAnimateTransition(transitionContext: UIViewControllerContextTransitioning) { + public func presentAnimateTransition(transitionContext: UIViewControllerContextTransitioning) { - var alertController = transitionContext.viewControllerForKey(UITransitionContextToViewControllerKey) as! DOAlertController - var containerView = transitionContext.containerView() + let alertController = transitionContext.viewControllerForKey(UITransitionContextToViewControllerKey) as! DOAlertController + let containerView = transitionContext.containerView() alertController.overlayView.alpha = 0.0 if (alertController.isAlert()) { @@ -92,7 +92,7 @@ class DOAlertAnimation : NSObject, UIViewControllerAnimatedTransitioning { } else { alertController.alertView.transform = CGAffineTransformMakeTranslation(0, alertController.alertView.frame.height) } - containerView.addSubview(alertController.view) + containerView!.addSubview(alertController.view) UIView.animateWithDuration(0.25, animations: { @@ -118,9 +118,9 @@ class DOAlertAnimation : NSObject, UIViewControllerAnimatedTransitioning { }) } - func dismissAnimateTransition(transitionContext: UIViewControllerContextTransitioning) { + public func dismissAnimateTransition(transitionContext: UIViewControllerContextTransitioning) { - var alertController = transitionContext.viewControllerForKey(UITransitionContextFromViewControllerKey) as! DOAlertController + let alertController = transitionContext.viewControllerForKey(UITransitionContextFromViewControllerKey) as! DOAlertController UIView.animateWithDuration(self.transitionDuration(transitionContext), animations: { @@ -140,17 +140,17 @@ class DOAlertAnimation : NSObject, UIViewControllerAnimatedTransitioning { // MARK: DOAlertController Class -class DOAlertController : UIViewController, UITextFieldDelegate, UIViewControllerTransitioningDelegate { +public class DOAlertController : UIViewController, UITextFieldDelegate, UIViewControllerTransitioningDelegate { // Message - var message: String? + public var message: String? // AlertController Style private(set) var preferredStyle: DOAlertControllerStyle? // OverlayView private var overlayView = UIView() - var overlayColor = UIColor(red:0, green:0, blue:0, alpha:0.5) + public var overlayColor = UIColor(red:0, green:0, blue:0, alpha:0.5) // ContainerView private var containerView = UIView() @@ -158,7 +158,7 @@ class DOAlertController : UIViewController, UITextFieldDelegate, UIViewControlle // AlertView private var alertView = UIView() - var alertViewBgColor = UIColor(red:239/255, green:240/255, blue:242/255, alpha:1.0) + public var alertViewBgColor = UIColor(red:239/255, green:240/255, blue:242/255, alpha:1.0) private var alertViewWidth: CGFloat = 270.0 private var alertViewHeightConstraint: NSLayoutConstraint! private var alertViewPadding: CGFloat = 15.0 @@ -178,22 +178,22 @@ class DOAlertController : UIViewController, UITextFieldDelegate, UIViewControlle // TitleLabel private var titleLabel = UILabel() - var titleFont = UIFont(name: "HelveticaNeue-Bold", size: 18) - var titleTextColor = UIColor(red:77/255, green:77/255, blue:77/255, alpha:1.0) + public var titleFont = UIFont(name: "HelveticaNeue-Bold", size: 18) + public var titleTextColor = UIColor(red:77/255, green:77/255, blue:77/255, alpha:1.0) // MessageView private var messageView = UILabel() - var messageFont = UIFont(name: "HelveticaNeue", size: 15) - var messageTextColor = UIColor(red:77/255, green:77/255, blue:77/255, alpha:1.0) + public var messageFont = UIFont(name: "HelveticaNeue", size: 15) + public var messageTextColor = UIColor(red:77/255, green:77/255, blue:77/255, alpha:1.0) // TextFieldContainerView private var textFieldContainerView = UIView() - var textFieldBorderColor = UIColor(red: 203.0/255, green: 203.0/255, blue: 203.0/255, alpha: 1.0) + public var textFieldBorderColor = UIColor(red: 203.0/255, green: 203.0/255, blue: 203.0/255, alpha: 1.0) // TextFields private(set) var textFields: [AnyObject]? private let textFieldHeight: CGFloat = 30.0 - var textFieldBgColor = UIColor.whiteColor() + public var textFieldBgColor = UIColor.whiteColor() private let textFieldCornerRadius: CGFloat = 4.0 // ButtonAreaScrollView @@ -215,22 +215,22 @@ class DOAlertController : UIViewController, UITextFieldDelegate, UIViewControlle // Buttons private var buttons = [UIButton]() - var buttonFont: [DOAlertActionStyle : UIFont!] = [ + public var buttonFont: [DOAlertActionStyle : UIFont!] = [ .Default : UIFont(name: "HelveticaNeue-Bold", size: 16), .Cancel : UIFont(name: "HelveticaNeue-Bold", size: 16), .Destructive : UIFont(name: "HelveticaNeue-Bold", size: 16) ] - var buttonTextColor: [DOAlertActionStyle : UIColor] = [ + public var buttonTextColor: [DOAlertActionStyle : UIColor] = [ .Default : UIColor.whiteColor(), .Cancel : UIColor.whiteColor(), .Destructive : UIColor.whiteColor() ] - var buttonBgColor: [DOAlertActionStyle : UIColor] = [ + public var buttonBgColor: [DOAlertActionStyle : UIColor] = [ .Default : UIColor(red:52/255, green:152/255, blue:219/255, alpha:1), .Cancel : UIColor(red:127/255, green:140/255, blue:141/255, alpha:1), .Destructive : UIColor(red:231/255, green:76/255, blue:60/255, alpha:1) ] - var buttonBgColorHighlighted: [DOAlertActionStyle : UIColor] = [ + public var buttonBgColorHighlighted: [DOAlertActionStyle : UIColor] = [ .Default : UIColor(red:74/255, green:163/255, blue:223/255, alpha:1), .Cancel : UIColor(red:140/255, green:152/255, blue:153/255, alpha:1), .Destructive : UIColor(red:234/255, green:97/255, blue:83/255, alpha:1) @@ -242,7 +242,7 @@ class DOAlertController : UIViewController, UITextFieldDelegate, UIViewControlle private var cancelButtonTag = 0 // Initializer - convenience init(title: String?, message: String?, preferredStyle: DOAlertControllerStyle) { + public convenience init(title: String?, message: String?, preferredStyle: DOAlertControllerStyle) { self.init(nibName: nil, bundle: nil) self.title = title @@ -311,15 +311,15 @@ class DOAlertController : UIViewController, UITextFieldDelegate, UIViewControlle //------------------------------ // Layout Constraint //------------------------------ - overlayView.setTranslatesAutoresizingMaskIntoConstraints(false) - containerView.setTranslatesAutoresizingMaskIntoConstraints(false) - alertView.setTranslatesAutoresizingMaskIntoConstraints(false) - textAreaScrollView.setTranslatesAutoresizingMaskIntoConstraints(false) - textAreaView.setTranslatesAutoresizingMaskIntoConstraints(false) - textContainer.setTranslatesAutoresizingMaskIntoConstraints(false) - buttonAreaScrollView.setTranslatesAutoresizingMaskIntoConstraints(false) - buttonAreaView.setTranslatesAutoresizingMaskIntoConstraints(false) - buttonContainer.setTranslatesAutoresizingMaskIntoConstraints(false) + overlayView.translatesAutoresizingMaskIntoConstraints = false + containerView.translatesAutoresizingMaskIntoConstraints = false + alertView.translatesAutoresizingMaskIntoConstraints = false + textAreaScrollView.translatesAutoresizingMaskIntoConstraints = false + textAreaView.translatesAutoresizingMaskIntoConstraints = false + textContainer.translatesAutoresizingMaskIntoConstraints = false + buttonAreaScrollView.translatesAutoresizingMaskIntoConstraints = false + buttonAreaView.translatesAutoresizingMaskIntoConstraints = false + buttonContainer.translatesAutoresizingMaskIntoConstraints = false // self.view let overlayViewTopSpaceConstraint = NSLayoutConstraint(item: overlayView, attribute: .Top, relatedBy: .Equal, toItem: self.view, attribute: .Top, multiplier: 1.0, constant: 0.0) @@ -405,29 +405,29 @@ class DOAlertController : UIViewController, UITextFieldDelegate, UIViewControlle buttonContainer.addConstraints([buttonContainerWidthConstraint, buttonContainerHeightConstraint]) } - override init(nibName nibNameOrNil: String?, bundle nibBundleOrNil: NSBundle?) { + public override init(nibName nibNameOrNil: String?, bundle nibBundleOrNil: NSBundle?) { super.init(nibName:nibNameOrNil, bundle:nibBundleOrNil) } - required init(coder aDecoder: NSCoder) { + public required init?(coder aDecoder: NSCoder) { fatalError("init(coder:) has not been implemented") } - override func viewWillAppear(animated: Bool) { + public override func viewWillAppear(animated: Bool) { super.viewWillAppear(animated) layoutView() } - override func viewDidAppear(animated: Bool) { + public override func viewDidAppear(animated: Bool) { super.viewDidAppear(animated) if (!isAlert() && cancelButtonTag != 0) { - var tapGesture = UITapGestureRecognizer(target: self, action: "handleContainerViewTapGesture:") + let tapGesture = UITapGestureRecognizer(target: self, action: "handleContainerViewTapGesture:") containerView.addGestureRecognizer(tapGesture) } } - func layoutView() { + public func layoutView() { if (layoutFlg) { return } layoutFlg = true @@ -489,7 +489,7 @@ class DOAlertController : UIViewController, UITextFieldDelegate, UIViewControlle var textFieldContainerHeight: CGFloat = 0.0 // TextFields - for (i, obj) in enumerate(textFields!) { + for (i, obj) in (textFields!).enumerate() { let textField = obj as! UITextField textField.frame = CGRectMake(0.0, textFieldContainerHeight, innerContentWidth, textField.frame.height) textFieldContainerHeight += textField.frame.height + 0.5 @@ -550,7 +550,7 @@ class DOAlertController : UIViewController, UITextFieldDelegate, UIViewControlle if (!isAlert() && buttons.count > 1) { buttonAreaPositionY += buttonMargin } - var button = buttonAreaScrollView.viewWithTag(cancelButtonTag) as! UIButton + let button = buttonAreaScrollView.viewWithTag(cancelButtonTag) as! UIButton let action = actions[cancelButtonTag - 1] as! DOAlertAction button.titleLabel?.font = buttonFont[action.style] button.setTitleColor(buttonTextColor[action.style], forState: .Normal) @@ -582,7 +582,7 @@ class DOAlertController : UIViewController, UITextFieldDelegate, UIViewControlle } // Reload AlertView Height - func reloadAlertViewHeight() { + public func reloadAlertViewHeight() { var screenSize = UIScreen.mainScreen().bounds.size if ((UIDevice.currentDevice().systemVersion as NSString).floatValue < 8.0) { @@ -614,7 +614,7 @@ class DOAlertController : UIViewController, UITextFieldDelegate, UIViewControlle } // Button Tapped Action - func buttonTapped(sender: UIButton) { + public func buttonTapped(sender: UIButton) { sender.selected = true let action = actions[sender.tag - 1] as! DOAlertAction if (action.handler != nil) { @@ -624,7 +624,7 @@ class DOAlertController : UIViewController, UITextFieldDelegate, UIViewControlle } // Handle ContainerView tap gesture - func handleContainerViewTapGesture(sender: AnyObject) { + public func handleContainerViewTapGesture(sender: AnyObject) { // cancel action let action = actions[cancelButtonTag] as! DOAlertAction if (action.handler != nil) { @@ -634,10 +634,10 @@ class DOAlertController : UIViewController, UITextFieldDelegate, UIViewControlle } // UIColor -> UIImage - func createImageFromUIColor(var color: UIColor) -> UIImage { + public func createImageFromUIColor(color: UIColor) -> UIImage { let rect = CGRectMake(0, 0, 1, 1) UIGraphicsBeginImageContext(rect.size) - let contextRef: CGContextRef = UIGraphicsGetCurrentContext() + let contextRef: CGContextRef = UIGraphicsGetCurrentContext()! CGContextSetFillColorWithColor(contextRef, color.CGColor) CGContextFillRect(contextRef, rect) let img: UIImage = UIGraphicsGetImageFromCurrentImageContext() @@ -647,13 +647,13 @@ class DOAlertController : UIViewController, UITextFieldDelegate, UIViewControlle // MARK : Handle NSNotification Method - @objc func handleAlertActionEnabledDidChangeNotification(notification: NSNotification) { + @objc public func handleAlertActionEnabledDidChangeNotification(notification: NSNotification) { for i in 0.. Void)!) { + public func addTextFieldWithConfigurationHandler(configurationHandler: ((UITextField!) -> Void)!) { // You can add a text field only if the preferredStyle property is set to DOAlertControllerStyle.Alert. if (!isAlert()) { - var error: NSError? - NSException.raise("NSInternalInconsistencyException", format: "Text fields can only be added to an alert controller of style DOAlertControllerStyleAlert", arguments:getVaList([error ?? "nil"])) + NSException.raise("NSInternalInconsistencyException", format: "Text fields can only be added to an alert controller of style DOAlertControllerStyleAlert", arguments:getVaList(["nil"])) return } if (textFields == nil) { textFields = [] } - var textField = UITextField() + let textField = UITextField() textField.frame.size = CGSizeMake(innerContentWidth, textFieldHeight) textField.borderStyle = UITextBorderStyle.None textField.backgroundColor = textFieldBgColor @@ -735,11 +734,11 @@ class DOAlertController : UIViewController, UITextFieldDelegate, UIViewControlle textFieldContainerView.addSubview(textField) } - func isAlert() -> Bool { return preferredStyle == .Alert } + public func isAlert() -> Bool { return preferredStyle == .Alert } // MARK: UITextFieldDelegate Methods - func textFieldShouldReturn(textField: UITextField) -> Bool { + public func textFieldShouldReturn(textField: UITextField) -> Bool { if (textField.canResignFirstResponder()) { textField.resignFirstResponder() self.dismissViewControllerAnimated(true, completion: nil) @@ -749,12 +748,12 @@ class DOAlertController : UIViewController, UITextFieldDelegate, UIViewControlle // MARK: UIViewControllerTransitioningDelegate Methods - func animationControllerForPresentedController(presented: UIViewController, presentingController presenting: UIViewController, sourceController source: UIViewController) -> UIViewControllerAnimatedTransitioning? { + public func animationControllerForPresentedController(presented: UIViewController, presentingController presenting: UIViewController, sourceController source: UIViewController) -> UIViewControllerAnimatedTransitioning? { layoutView() return DOAlertAnimation(isPresenting: true) } - func animationControllerForDismissedController(dismissed: UIViewController) -> UIViewControllerAnimatedTransitioning? { + public func animationControllerForDismissedController(dismissed: UIViewController) -> UIViewControllerAnimatedTransitioning? { return DOAlertAnimation(isPresenting: false) } } From d37e13d645b5e6cb1f9b551e0c23ebe442201833 Mon Sep 17 00:00:00 2001 From: Nicolas Klein Date: Thu, 17 Mar 2016 17:51:45 +0100 Subject: [PATCH 02/11] fixed the tap gesture on the base view calling a wrong action --- DOAlertController/DOAlertController.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/DOAlertController/DOAlertController.swift b/DOAlertController/DOAlertController.swift index 9e98853..8901e15 100644 --- a/DOAlertController/DOAlertController.swift +++ b/DOAlertController/DOAlertController.swift @@ -626,7 +626,7 @@ public class DOAlertController : UIViewController, UITextFieldDelegate, UIViewCo // Handle ContainerView tap gesture public func handleContainerViewTapGesture(sender: AnyObject) { // cancel action - let action = actions[cancelButtonTag] as! DOAlertAction + let action = actions[cancelButtonTag - 1] as! DOAlertAction if (action.handler != nil) { action.handler(action) } From ca7ca3fdd4f50f1dac72a815ab896a23fbd7f9c0 Mon Sep 17 00:00:00 2001 From: dulgan Date: Wed, 10 Aug 2016 16:55:05 +0200 Subject: [PATCH 03/11] Made containerView for AlertView public Made containerView for AlertView public in order to customize it as needed --- DOAlertController/DOAlertController.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/DOAlertController/DOAlertController.swift b/DOAlertController/DOAlertController.swift index 8901e15..26e0e92 100644 --- a/DOAlertController/DOAlertController.swift +++ b/DOAlertController/DOAlertController.swift @@ -153,7 +153,7 @@ public class DOAlertController : UIViewController, UITextFieldDelegate, UIViewCo public var overlayColor = UIColor(red:0, green:0, blue:0, alpha:0.5) // ContainerView - private var containerView = UIView() + public var containerView = UIView() private var containerViewBottomSpaceConstraint: NSLayoutConstraint! // AlertView From d34ab819e45aee910650ce225ca66b399a459dbf Mon Sep 17 00:00:00 2001 From: dulgan Date: Mon, 5 Sep 2016 11:13:56 +0200 Subject: [PATCH 04/11] Made alertView public --- DOAlertController/DOAlertController.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/DOAlertController/DOAlertController.swift b/DOAlertController/DOAlertController.swift index 26e0e92..2b5eef1 100644 --- a/DOAlertController/DOAlertController.swift +++ b/DOAlertController/DOAlertController.swift @@ -157,7 +157,7 @@ public class DOAlertController : UIViewController, UITextFieldDelegate, UIViewCo private var containerViewBottomSpaceConstraint: NSLayoutConstraint! // AlertView - private var alertView = UIView() + public var alertView = UIView() public var alertViewBgColor = UIColor(red:239/255, green:240/255, blue:242/255, alpha:1.0) private var alertViewWidth: CGFloat = 270.0 private var alertViewHeightConstraint: NSLayoutConstraint! From ce8d59d0ac87cbe839ca7237c65fdaee3e7cddd6 Mon Sep 17 00:00:00 2001 From: Nicolas Date: Mon, 3 Oct 2016 14:55:07 +0200 Subject: [PATCH 05/11] swift 3 update --- DOAlertController/DOAlertController.swift | 456 +++++++++++----------- 1 file changed, 228 insertions(+), 228 deletions(-) diff --git a/DOAlertController/DOAlertController.swift b/DOAlertController/DOAlertController.swift index 2b5eef1..9b6f29f 100644 --- a/DOAlertController/DOAlertController.swift +++ b/DOAlertController/DOAlertController.swift @@ -15,39 +15,39 @@ import UIKit let DOAlertActionEnabledDidChangeNotification = "DOAlertActionEnabledDidChangeNotification" public enum DOAlertActionStyle : Int { - case Default - case Cancel - case Destructive + case `default` + case cancel + case destructive } public enum DOAlertControllerStyle : Int { - case ActionSheet - case Alert + case actionSheet + case alert } // MARK: DOAlertAction Class -public class DOAlertAction : NSObject, NSCopying { - public var title: String - public var style: DOAlertActionStyle - public var handler: ((DOAlertAction!) -> Void)! - public var enabled: Bool { +open class DOAlertAction : NSObject, NSCopying { + open var title: String + open var style: DOAlertActionStyle + open var handler: ((DOAlertAction?) -> Void)! + open var enabled: Bool { didSet { if (oldValue != enabled) { - NSNotificationCenter.defaultCenter().postNotificationName(DOAlertActionEnabledDidChangeNotification, object: nil) + NotificationCenter.default.post(name: Notification.Name(rawValue: DOAlertActionEnabledDidChangeNotification), object: nil) } } } - public required init(title: String, style: DOAlertActionStyle, handler: ((DOAlertAction!) -> Void)!) { + public required init(title: String, style: DOAlertActionStyle, handler: ((DOAlertAction?) -> Void)!) { self.title = title self.style = style self.handler = handler self.enabled = true } - public func copyWithZone(zone: NSZone) -> AnyObject { - let copy = self.dynamicType.init(title: title, style: style, handler: handler) + open func copy(with zone: NSZone?) -> Any { + let copy = type(of: self).init(title: title, style: style, handler: handler) copy.enabled = self.enabled return copy } @@ -55,15 +55,15 @@ public class DOAlertAction : NSObject, NSCopying { // MARK: DOAlertAnimation Class -public class DOAlertAnimation : NSObject, UIViewControllerAnimatedTransitioning { +open class DOAlertAnimation : NSObject, UIViewControllerAnimatedTransitioning { - public let isPresenting: Bool + open let isPresenting: Bool public init(isPresenting: Bool) { self.isPresenting = isPresenting } - public func transitionDuration(transitionContext: UIViewControllerContextTransitioning?) -> NSTimeInterval { + open func transitionDuration(using transitionContext: UIViewControllerContextTransitioning?) -> TimeInterval { if (isPresenting) { return 0.45 } else { @@ -71,7 +71,7 @@ public class DOAlertAnimation : NSObject, UIViewControllerAnimatedTransitioning } } - public func animateTransition(transitionContext: UIViewControllerContextTransitioning) { + open func animateTransition(using transitionContext: UIViewControllerContextTransitioning) { if (isPresenting) { self.presentAnimateTransition(transitionContext) } else { @@ -79,36 +79,36 @@ public class DOAlertAnimation : NSObject, UIViewControllerAnimatedTransitioning } } - public func presentAnimateTransition(transitionContext: UIViewControllerContextTransitioning) { + open func presentAnimateTransition(_ transitionContext: UIViewControllerContextTransitioning) { - let alertController = transitionContext.viewControllerForKey(UITransitionContextToViewControllerKey) as! DOAlertController - let containerView = transitionContext.containerView() + let alertController = transitionContext.viewController(forKey: UITransitionContextViewControllerKey.to) as! DOAlertController + let containerView = transitionContext.containerView alertController.overlayView.alpha = 0.0 if (alertController.isAlert()) { alertController.alertView.alpha = 0.0 alertController.alertView.center = alertController.view.center - alertController.alertView.transform = CGAffineTransformMakeScale(0.5, 0.5) + alertController.alertView.transform = CGAffineTransform(scaleX: 0.5, y: 0.5) } else { - alertController.alertView.transform = CGAffineTransformMakeTranslation(0, alertController.alertView.frame.height) + alertController.alertView.transform = CGAffineTransform(translationX: 0, y: alertController.alertView.frame.height) } - containerView!.addSubview(alertController.view) + containerView.addSubview(alertController.view) - UIView.animateWithDuration(0.25, + UIView.animate(withDuration: 0.25, animations: { alertController.overlayView.alpha = 1.0 if (alertController.isAlert()) { alertController.alertView.alpha = 1.0 - alertController.alertView.transform = CGAffineTransformMakeScale(1.05, 1.05) + alertController.alertView.transform = CGAffineTransform(scaleX: 1.05, y: 1.05) } else { let bounce = alertController.alertView.frame.height / 480 * 10.0 + 10.0 - alertController.alertView.transform = CGAffineTransformMakeTranslation(0, -bounce) + alertController.alertView.transform = CGAffineTransform(translationX: 0, y: -bounce) } }, completion: { finished in - UIView.animateWithDuration(0.2, + UIView.animate(withDuration: 0.2, animations: { - alertController.alertView.transform = CGAffineTransformIdentity + alertController.alertView.transform = CGAffineTransform.identity }, completion: { finished in if (finished) { @@ -118,18 +118,18 @@ public class DOAlertAnimation : NSObject, UIViewControllerAnimatedTransitioning }) } - public func dismissAnimateTransition(transitionContext: UIViewControllerContextTransitioning) { + open func dismissAnimateTransition(_ transitionContext: UIViewControllerContextTransitioning) { - let alertController = transitionContext.viewControllerForKey(UITransitionContextFromViewControllerKey) as! DOAlertController + let alertController = transitionContext.viewController(forKey: UITransitionContextViewControllerKey.from) as! DOAlertController - UIView.animateWithDuration(self.transitionDuration(transitionContext), + UIView.animate(withDuration: self.transitionDuration(using: transitionContext), animations: { alertController.overlayView.alpha = 0.0 if (alertController.isAlert()) { alertController.alertView.alpha = 0.0 - alertController.alertView.transform = CGAffineTransformMakeScale(0.9, 0.9) + alertController.alertView.transform = CGAffineTransform(scaleX: 0.9, y: 0.9) } else { - alertController.containerView.transform = CGAffineTransformMakeTranslation(0, alertController.alertView.frame.height) + alertController.containerView.transform = CGAffineTransform(translationX: 0, y: alertController.alertView.frame.height) } }, completion: { finished in @@ -140,106 +140,106 @@ public class DOAlertAnimation : NSObject, UIViewControllerAnimatedTransitioning // MARK: DOAlertController Class -public class DOAlertController : UIViewController, UITextFieldDelegate, UIViewControllerTransitioningDelegate { +open class DOAlertController : UIViewController, UITextFieldDelegate, UIViewControllerTransitioningDelegate { // Message - public var message: String? + open var message: String? // AlertController Style - private(set) var preferredStyle: DOAlertControllerStyle? + fileprivate(set) var preferredStyle: DOAlertControllerStyle? // OverlayView - private var overlayView = UIView() - public var overlayColor = UIColor(red:0, green:0, blue:0, alpha:0.5) + fileprivate var overlayView = UIView() + open var overlayColor = UIColor(red:0, green:0, blue:0, alpha:0.5) // ContainerView - public var containerView = UIView() - private var containerViewBottomSpaceConstraint: NSLayoutConstraint! + open var containerView = UIView() + fileprivate var containerViewBottomSpaceConstraint: NSLayoutConstraint! // AlertView - public var alertView = UIView() - public var alertViewBgColor = UIColor(red:239/255, green:240/255, blue:242/255, alpha:1.0) - private var alertViewWidth: CGFloat = 270.0 - private var alertViewHeightConstraint: NSLayoutConstraint! - private var alertViewPadding: CGFloat = 15.0 - private var innerContentWidth: CGFloat = 240.0 - private let actionSheetBounceHeight: CGFloat = 20.0 + open var alertView = UIView() + open var alertViewBgColor = UIColor(red:239/255, green:240/255, blue:242/255, alpha:1.0) + fileprivate var alertViewWidth: CGFloat = 270.0 + fileprivate var alertViewHeightConstraint: NSLayoutConstraint! + fileprivate var alertViewPadding: CGFloat = 15.0 + fileprivate var innerContentWidth: CGFloat = 240.0 + fileprivate let actionSheetBounceHeight: CGFloat = 20.0 // TextAreaScrollView - private var textAreaScrollView = UIScrollView() - private var textAreaHeight: CGFloat = 0.0 + fileprivate var textAreaScrollView = UIScrollView() + fileprivate var textAreaHeight: CGFloat = 0.0 // TextAreaView - private var textAreaView = UIView() + fileprivate var textAreaView = UIView() // TextContainer - private var textContainer = UIView() - private var textContainerHeightConstraint: NSLayoutConstraint! + fileprivate var textContainer = UIView() + fileprivate var textContainerHeightConstraint: NSLayoutConstraint! // TitleLabel - private var titleLabel = UILabel() - public var titleFont = UIFont(name: "HelveticaNeue-Bold", size: 18) - public var titleTextColor = UIColor(red:77/255, green:77/255, blue:77/255, alpha:1.0) + fileprivate var titleLabel = UILabel() + open var titleFont = UIFont(name: "HelveticaNeue-Bold", size: 18) + open var titleTextColor = UIColor(red:77/255, green:77/255, blue:77/255, alpha:1.0) // MessageView - private var messageView = UILabel() - public var messageFont = UIFont(name: "HelveticaNeue", size: 15) - public var messageTextColor = UIColor(red:77/255, green:77/255, blue:77/255, alpha:1.0) + fileprivate var messageView = UILabel() + open var messageFont = UIFont(name: "HelveticaNeue", size: 15) + open var messageTextColor = UIColor(red:77/255, green:77/255, blue:77/255, alpha:1.0) // TextFieldContainerView - private var textFieldContainerView = UIView() - public var textFieldBorderColor = UIColor(red: 203.0/255, green: 203.0/255, blue: 203.0/255, alpha: 1.0) + fileprivate var textFieldContainerView = UIView() + open var textFieldBorderColor = UIColor(red: 203.0/255, green: 203.0/255, blue: 203.0/255, alpha: 1.0) // TextFields - private(set) var textFields: [AnyObject]? - private let textFieldHeight: CGFloat = 30.0 - public var textFieldBgColor = UIColor.whiteColor() - private let textFieldCornerRadius: CGFloat = 4.0 + fileprivate(set) var textFields: [AnyObject]? + fileprivate let textFieldHeight: CGFloat = 30.0 + open var textFieldBgColor = UIColor.white + fileprivate let textFieldCornerRadius: CGFloat = 4.0 // ButtonAreaScrollView - private var buttonAreaScrollView = UIScrollView() - private var buttonAreaScrollViewHeightConstraint: NSLayoutConstraint! - private var buttonAreaHeight: CGFloat = 0.0 + fileprivate var buttonAreaScrollView = UIScrollView() + fileprivate var buttonAreaScrollViewHeightConstraint: NSLayoutConstraint! + fileprivate var buttonAreaHeight: CGFloat = 0.0 // ButtonAreaView - private var buttonAreaView = UIView() + fileprivate var buttonAreaView = UIView() // ButtonContainer - private var buttonContainer = UIView() - private var buttonContainerHeightConstraint: NSLayoutConstraint! - private let buttonHeight: CGFloat = 44.0 - private var buttonMargin: CGFloat = 10.0 + fileprivate var buttonContainer = UIView() + fileprivate var buttonContainerHeightConstraint: NSLayoutConstraint! + fileprivate let buttonHeight: CGFloat = 44.0 + fileprivate var buttonMargin: CGFloat = 10.0 // Actions - private(set) var actions: [AnyObject] = [] + fileprivate(set) var actions: [AnyObject] = [] // Buttons - private var buttons = [UIButton]() - public var buttonFont: [DOAlertActionStyle : UIFont!] = [ - .Default : UIFont(name: "HelveticaNeue-Bold", size: 16), - .Cancel : UIFont(name: "HelveticaNeue-Bold", size: 16), - .Destructive : UIFont(name: "HelveticaNeue-Bold", size: 16) + fileprivate var buttons = [UIButton]() + open var buttonFont: [DOAlertActionStyle : UIFont?] = [ + .default : UIFont(name: "HelveticaNeue-Bold", size: 16), + .cancel : UIFont(name: "HelveticaNeue-Bold", size: 16), + .destructive : UIFont(name: "HelveticaNeue-Bold", size: 16) ] - public var buttonTextColor: [DOAlertActionStyle : UIColor] = [ - .Default : UIColor.whiteColor(), - .Cancel : UIColor.whiteColor(), - .Destructive : UIColor.whiteColor() + open var buttonTextColor: [DOAlertActionStyle : UIColor] = [ + .default : UIColor.white, + .cancel : UIColor.white, + .destructive : UIColor.white ] - public var buttonBgColor: [DOAlertActionStyle : UIColor] = [ - .Default : UIColor(red:52/255, green:152/255, blue:219/255, alpha:1), - .Cancel : UIColor(red:127/255, green:140/255, blue:141/255, alpha:1), - .Destructive : UIColor(red:231/255, green:76/255, blue:60/255, alpha:1) + open var buttonBgColor: [DOAlertActionStyle : UIColor] = [ + .default : UIColor(red:52/255, green:152/255, blue:219/255, alpha:1), + .cancel : UIColor(red:127/255, green:140/255, blue:141/255, alpha:1), + .destructive : UIColor(red:231/255, green:76/255, blue:60/255, alpha:1) ] - public var buttonBgColorHighlighted: [DOAlertActionStyle : UIColor] = [ - .Default : UIColor(red:74/255, green:163/255, blue:223/255, alpha:1), - .Cancel : UIColor(red:140/255, green:152/255, blue:153/255, alpha:1), - .Destructive : UIColor(red:234/255, green:97/255, blue:83/255, alpha:1) + open var buttonBgColorHighlighted: [DOAlertActionStyle : UIColor] = [ + .default : UIColor(red:74/255, green:163/255, blue:223/255, alpha:1), + .cancel : UIColor(red:140/255, green:152/255, blue:153/255, alpha:1), + .destructive : UIColor(red:234/255, green:97/255, blue:83/255, alpha:1) ] - private var buttonCornerRadius: CGFloat = 4.0 + fileprivate var buttonCornerRadius: CGFloat = 4.0 - private var layoutFlg = false - private var keyboardHeight: CGFloat = 0.0 - private var cancelButtonTag = 0 + fileprivate var layoutFlg = false + fileprivate var keyboardHeight: CGFloat = 0.0 + fileprivate var cancelButtonTag = 0 // Initializer public convenience init(title: String?, message: String?, preferredStyle: DOAlertControllerStyle) { @@ -251,21 +251,21 @@ public class DOAlertController : UIViewController, UITextFieldDelegate, UIViewCo self.providesPresentationContextTransitionStyle = true self.definesPresentationContext = true - self.modalPresentationStyle = UIModalPresentationStyle.Custom + self.modalPresentationStyle = UIModalPresentationStyle.custom // NotificationCenter - NSNotificationCenter.defaultCenter().addObserver(self, selector: "handleAlertActionEnabledDidChangeNotification:", name: DOAlertActionEnabledDidChangeNotification, object: nil) - NSNotificationCenter.defaultCenter().addObserver(self, selector: "handleKeyboardWillShowNotification:", name: UIKeyboardWillShowNotification, object: nil) - NSNotificationCenter.defaultCenter().addObserver(self, selector: "handleKeyboardWillHideNotification:", name: UIKeyboardWillHideNotification, object: nil) + NotificationCenter.default.addObserver(self, selector: #selector(DOAlertController.handleAlertActionEnabledDidChangeNotification(_:)), name: NSNotification.Name(rawValue: DOAlertActionEnabledDidChangeNotification), object: nil) + NotificationCenter.default.addObserver(self, selector: #selector(DOAlertController.handleKeyboardWillShowNotification(_:)), name: NSNotification.Name.UIKeyboardWillShow, object: nil) + NotificationCenter.default.addObserver(self, selector: #selector(DOAlertController.handleKeyboardWillHideNotification(_:)), name: NSNotification.Name.UIKeyboardWillHide, object: nil) // Delegate self.transitioningDelegate = self // Screen Size - var screenSize = UIScreen.mainScreen().bounds.size - if ((UIDevice.currentDevice().systemVersion as NSString).floatValue < 8.0) { - if (UIInterfaceOrientationIsLandscape(UIApplication.sharedApplication().statusBarOrientation)) { - screenSize = CGSizeMake(screenSize.height, screenSize.width) + var screenSize = UIScreen.main.bounds.size + if ((UIDevice.current.systemVersion as NSString).floatValue < 8.0) { + if (UIInterfaceOrientationIsLandscape(UIApplication.shared.statusBarOrientation)) { + screenSize = CGSize(width: screenSize.height, height: screenSize.width) } } @@ -322,90 +322,90 @@ public class DOAlertController : UIViewController, UITextFieldDelegate, UIViewCo buttonContainer.translatesAutoresizingMaskIntoConstraints = false // self.view - let overlayViewTopSpaceConstraint = NSLayoutConstraint(item: overlayView, attribute: .Top, relatedBy: .Equal, toItem: self.view, attribute: .Top, multiplier: 1.0, constant: 0.0) - let overlayViewRightSpaceConstraint = NSLayoutConstraint(item: overlayView, attribute: .Right, relatedBy: .Equal, toItem: self.view, attribute: .Right, multiplier: 1.0, constant: 0.0) - let overlayViewLeftSpaceConstraint = NSLayoutConstraint(item: overlayView, attribute: .Left, relatedBy: .Equal, toItem: self.view, attribute: .Left, multiplier: 1.0, constant: 0.0) - let overlayViewBottomSpaceConstraint = NSLayoutConstraint(item: overlayView, attribute: .Bottom, relatedBy: .Equal, toItem: self.view, attribute: .Bottom, multiplier: 1.0, constant: 0.0) - let containerViewTopSpaceConstraint = NSLayoutConstraint(item: containerView, attribute: .Top, relatedBy: .Equal, toItem: self.view, attribute: .Top, multiplier: 1.0, constant: 0.0) - let containerViewRightSpaceConstraint = NSLayoutConstraint(item: containerView, attribute: .Right, relatedBy: .Equal, toItem: self.view, attribute: .Right, multiplier: 1.0, constant: 0.0) - let containerViewLeftSpaceConstraint = NSLayoutConstraint(item: containerView, attribute: .Left, relatedBy: .Equal, toItem: self.view, attribute: .Left, multiplier: 1.0, constant: 0.0) - containerViewBottomSpaceConstraint = NSLayoutConstraint(item: containerView, attribute: .Bottom, relatedBy: .Equal, toItem: self.view, attribute: .Bottom, multiplier: 1.0, constant: 0.0) + let overlayViewTopSpaceConstraint = NSLayoutConstraint(item: overlayView, attribute: .top, relatedBy: .equal, toItem: self.view, attribute: .top, multiplier: 1.0, constant: 0.0) + let overlayViewRightSpaceConstraint = NSLayoutConstraint(item: overlayView, attribute: .right, relatedBy: .equal, toItem: self.view, attribute: .right, multiplier: 1.0, constant: 0.0) + let overlayViewLeftSpaceConstraint = NSLayoutConstraint(item: overlayView, attribute: .left, relatedBy: .equal, toItem: self.view, attribute: .left, multiplier: 1.0, constant: 0.0) + let overlayViewBottomSpaceConstraint = NSLayoutConstraint(item: overlayView, attribute: .bottom, relatedBy: .equal, toItem: self.view, attribute: .bottom, multiplier: 1.0, constant: 0.0) + let containerViewTopSpaceConstraint = NSLayoutConstraint(item: containerView, attribute: .top, relatedBy: .equal, toItem: self.view, attribute: .top, multiplier: 1.0, constant: 0.0) + let containerViewRightSpaceConstraint = NSLayoutConstraint(item: containerView, attribute: .right, relatedBy: .equal, toItem: self.view, attribute: .right, multiplier: 1.0, constant: 0.0) + let containerViewLeftSpaceConstraint = NSLayoutConstraint(item: containerView, attribute: .left, relatedBy: .equal, toItem: self.view, attribute: .left, multiplier: 1.0, constant: 0.0) + containerViewBottomSpaceConstraint = NSLayoutConstraint(item: containerView, attribute: .bottom, relatedBy: .equal, toItem: self.view, attribute: .bottom, multiplier: 1.0, constant: 0.0) self.view.addConstraints([overlayViewTopSpaceConstraint, overlayViewRightSpaceConstraint, overlayViewLeftSpaceConstraint, overlayViewBottomSpaceConstraint, containerViewTopSpaceConstraint, containerViewRightSpaceConstraint, containerViewLeftSpaceConstraint, containerViewBottomSpaceConstraint]) if (isAlert()) { // ContainerView - let alertViewCenterXConstraint = NSLayoutConstraint(item: alertView, attribute: .CenterX, relatedBy: .Equal, toItem: containerView, attribute: .CenterX, multiplier: 1.0, constant: 0.0) - let alertViewCenterYConstraint = NSLayoutConstraint(item: alertView, attribute: .CenterY, relatedBy: .Equal, toItem: containerView, attribute: .CenterY, multiplier: 1.0, constant: 0.0) + let alertViewCenterXConstraint = NSLayoutConstraint(item: alertView, attribute: .centerX, relatedBy: .equal, toItem: containerView, attribute: .centerX, multiplier: 1.0, constant: 0.0) + let alertViewCenterYConstraint = NSLayoutConstraint(item: alertView, attribute: .centerY, relatedBy: .equal, toItem: containerView, attribute: .centerY, multiplier: 1.0, constant: 0.0) containerView.addConstraints([alertViewCenterXConstraint, alertViewCenterYConstraint]) // AlertView - let alertViewWidthConstraint = NSLayoutConstraint(item: alertView, attribute: .Width, relatedBy: .Equal, toItem: nil, attribute: .Width, multiplier: 1.0, constant: alertViewWidth) - alertViewHeightConstraint = NSLayoutConstraint(item: alertView, attribute: .Height, relatedBy: .Equal, toItem: nil, attribute: .Height, multiplier: 1.0, constant: 1000.0) + let alertViewWidthConstraint = NSLayoutConstraint(item: alertView, attribute: .width, relatedBy: .equal, toItem: nil, attribute: .width, multiplier: 1.0, constant: alertViewWidth) + alertViewHeightConstraint = NSLayoutConstraint(item: alertView, attribute: .height, relatedBy: .equal, toItem: nil, attribute: .height, multiplier: 1.0, constant: 1000.0) alertView.addConstraints([alertViewWidthConstraint, alertViewHeightConstraint]) } else { // ContainerView - let alertViewCenterXConstraint = NSLayoutConstraint(item: alertView, attribute: .CenterX, relatedBy: .Equal, toItem: containerView, attribute: .CenterX, multiplier: 1.0, constant: 0.0) - let alertViewBottomSpaceConstraint = NSLayoutConstraint(item: alertView, attribute: .Bottom, relatedBy: .Equal, toItem: containerView, attribute: .Bottom, multiplier: 1.0, constant: actionSheetBounceHeight) - let alertViewWidthConstraint = NSLayoutConstraint(item: alertView, attribute: .Width, relatedBy: .Equal, toItem: containerView, attribute: .Width, multiplier: 1.0, constant: 0.0) + let alertViewCenterXConstraint = NSLayoutConstraint(item: alertView, attribute: .centerX, relatedBy: .equal, toItem: containerView, attribute: .centerX, multiplier: 1.0, constant: 0.0) + let alertViewBottomSpaceConstraint = NSLayoutConstraint(item: alertView, attribute: .bottom, relatedBy: .equal, toItem: containerView, attribute: .bottom, multiplier: 1.0, constant: actionSheetBounceHeight) + let alertViewWidthConstraint = NSLayoutConstraint(item: alertView, attribute: .width, relatedBy: .equal, toItem: containerView, attribute: .width, multiplier: 1.0, constant: 0.0) containerView.addConstraints([alertViewCenterXConstraint, alertViewBottomSpaceConstraint, alertViewWidthConstraint]) // AlertView - alertViewHeightConstraint = NSLayoutConstraint(item: alertView, attribute: .Height, relatedBy: .Equal, toItem: nil, attribute: .Height, multiplier: 1.0, constant: 1000.0) + alertViewHeightConstraint = NSLayoutConstraint(item: alertView, attribute: .height, relatedBy: .equal, toItem: nil, attribute: .height, multiplier: 1.0, constant: 1000.0) alertView.addConstraint(alertViewHeightConstraint) } // AlertView - let textAreaScrollViewTopSpaceConstraint = NSLayoutConstraint(item: textAreaScrollView, attribute: .Top, relatedBy: .Equal, toItem: alertView, attribute: .Top, multiplier: 1.0, constant: 0.0) - let textAreaScrollViewRightSpaceConstraint = NSLayoutConstraint(item: textAreaScrollView, attribute: .Right, relatedBy: .Equal, toItem: alertView, attribute: .Right, multiplier: 1.0, constant: 0.0) - let textAreaScrollViewLeftSpaceConstraint = NSLayoutConstraint(item: textAreaScrollView, attribute: .Left, relatedBy: .Equal, toItem: alertView, attribute: .Left, multiplier: 1.0, constant: 0.0) - let textAreaScrollViewBottomSpaceConstraint = NSLayoutConstraint(item: textAreaScrollView, attribute: .Bottom, relatedBy: .Equal, toItem: buttonAreaScrollView, attribute: .Top, multiplier: 1.0, constant: 0.0) - let buttonAreaScrollViewRightSpaceConstraint = NSLayoutConstraint(item: buttonAreaScrollView, attribute: .Right, relatedBy: .Equal, toItem: alertView, attribute: .Right, multiplier: 1.0, constant: 0.0) - let buttonAreaScrollViewLeftSpaceConstraint = NSLayoutConstraint(item: buttonAreaScrollView, attribute: .Left, relatedBy: .Equal, toItem: alertView, attribute: .Left, multiplier: 1.0, constant: 0.0) - let buttonAreaScrollViewBottomSpaceConstraint = NSLayoutConstraint(item: buttonAreaScrollView, attribute: .Bottom, relatedBy: .Equal, toItem: alertView, attribute: .Bottom, multiplier: 1.0, constant: isAlert() ? 0.0 : -actionSheetBounceHeight) + let textAreaScrollViewTopSpaceConstraint = NSLayoutConstraint(item: textAreaScrollView, attribute: .top, relatedBy: .equal, toItem: alertView, attribute: .top, multiplier: 1.0, constant: 0.0) + let textAreaScrollViewRightSpaceConstraint = NSLayoutConstraint(item: textAreaScrollView, attribute: .right, relatedBy: .equal, toItem: alertView, attribute: .right, multiplier: 1.0, constant: 0.0) + let textAreaScrollViewLeftSpaceConstraint = NSLayoutConstraint(item: textAreaScrollView, attribute: .left, relatedBy: .equal, toItem: alertView, attribute: .left, multiplier: 1.0, constant: 0.0) + let textAreaScrollViewBottomSpaceConstraint = NSLayoutConstraint(item: textAreaScrollView, attribute: .bottom, relatedBy: .equal, toItem: buttonAreaScrollView, attribute: .top, multiplier: 1.0, constant: 0.0) + let buttonAreaScrollViewRightSpaceConstraint = NSLayoutConstraint(item: buttonAreaScrollView, attribute: .right, relatedBy: .equal, toItem: alertView, attribute: .right, multiplier: 1.0, constant: 0.0) + let buttonAreaScrollViewLeftSpaceConstraint = NSLayoutConstraint(item: buttonAreaScrollView, attribute: .left, relatedBy: .equal, toItem: alertView, attribute: .left, multiplier: 1.0, constant: 0.0) + let buttonAreaScrollViewBottomSpaceConstraint = NSLayoutConstraint(item: buttonAreaScrollView, attribute: .bottom, relatedBy: .equal, toItem: alertView, attribute: .bottom, multiplier: 1.0, constant: isAlert() ? 0.0 : -actionSheetBounceHeight) alertView.addConstraints([textAreaScrollViewTopSpaceConstraint, textAreaScrollViewRightSpaceConstraint, textAreaScrollViewLeftSpaceConstraint, textAreaScrollViewBottomSpaceConstraint, buttonAreaScrollViewRightSpaceConstraint, buttonAreaScrollViewLeftSpaceConstraint, buttonAreaScrollViewBottomSpaceConstraint]) // TextAreaScrollView - let textAreaViewTopSpaceConstraint = NSLayoutConstraint(item: textAreaView, attribute: .Top, relatedBy: .Equal, toItem: textAreaScrollView, attribute: .Top, multiplier: 1.0, constant: 0.0) - let textAreaViewRightSpaceConstraint = NSLayoutConstraint(item: textAreaView, attribute: .Right, relatedBy: .Equal, toItem: textAreaScrollView, attribute: .Right, multiplier: 1.0, constant: 0.0) - let textAreaViewLeftSpaceConstraint = NSLayoutConstraint(item: textAreaView, attribute: .Left, relatedBy: .Equal, toItem: textAreaScrollView, attribute: .Left, multiplier: 1.0, constant: 0.0) - let textAreaViewBottomSpaceConstraint = NSLayoutConstraint(item: textAreaView, attribute: .Bottom, relatedBy: .Equal, toItem: textAreaScrollView, attribute: .Bottom, multiplier: 1.0, constant: 0.0) - let textAreaViewWidthConstraint = NSLayoutConstraint(item: textAreaView, attribute: .Width, relatedBy: .Equal, toItem: textAreaScrollView, attribute: .Width, multiplier: 1.0, constant: 0.0) + let textAreaViewTopSpaceConstraint = NSLayoutConstraint(item: textAreaView, attribute: .top, relatedBy: .equal, toItem: textAreaScrollView, attribute: .top, multiplier: 1.0, constant: 0.0) + let textAreaViewRightSpaceConstraint = NSLayoutConstraint(item: textAreaView, attribute: .right, relatedBy: .equal, toItem: textAreaScrollView, attribute: .right, multiplier: 1.0, constant: 0.0) + let textAreaViewLeftSpaceConstraint = NSLayoutConstraint(item: textAreaView, attribute: .left, relatedBy: .equal, toItem: textAreaScrollView, attribute: .left, multiplier: 1.0, constant: 0.0) + let textAreaViewBottomSpaceConstraint = NSLayoutConstraint(item: textAreaView, attribute: .bottom, relatedBy: .equal, toItem: textAreaScrollView, attribute: .bottom, multiplier: 1.0, constant: 0.0) + let textAreaViewWidthConstraint = NSLayoutConstraint(item: textAreaView, attribute: .width, relatedBy: .equal, toItem: textAreaScrollView, attribute: .width, multiplier: 1.0, constant: 0.0) textAreaScrollView.addConstraints([textAreaViewTopSpaceConstraint, textAreaViewRightSpaceConstraint, textAreaViewLeftSpaceConstraint, textAreaViewBottomSpaceConstraint, textAreaViewWidthConstraint]) // TextArea - let textAreaViewHeightConstraint = NSLayoutConstraint(item: textAreaView, attribute: .Height, relatedBy: .Equal, toItem: textContainer, attribute: .Height, multiplier: 1.0, constant: 0.0) - let textContainerTopSpaceConstraint = NSLayoutConstraint(item: textContainer, attribute: .Top, relatedBy: .Equal, toItem: textAreaView, attribute: .Top, multiplier: 1.0, constant: 0.0) - let textContainerCenterXConstraint = NSLayoutConstraint(item: textContainer, attribute: .CenterX, relatedBy: .Equal, toItem: textAreaView, attribute: .CenterX, multiplier: 1.0, constant: 0.0) + let textAreaViewHeightConstraint = NSLayoutConstraint(item: textAreaView, attribute: .height, relatedBy: .equal, toItem: textContainer, attribute: .height, multiplier: 1.0, constant: 0.0) + let textContainerTopSpaceConstraint = NSLayoutConstraint(item: textContainer, attribute: .top, relatedBy: .equal, toItem: textAreaView, attribute: .top, multiplier: 1.0, constant: 0.0) + let textContainerCenterXConstraint = NSLayoutConstraint(item: textContainer, attribute: .centerX, relatedBy: .equal, toItem: textAreaView, attribute: .centerX, multiplier: 1.0, constant: 0.0) textAreaView.addConstraints([textAreaViewHeightConstraint, textContainerTopSpaceConstraint, textContainerCenterXConstraint]) // TextContainer - let textContainerWidthConstraint = NSLayoutConstraint(item: textContainer, attribute: .Width, relatedBy: .Equal, toItem: nil, attribute: .Width, multiplier: 1.0, constant: innerContentWidth) - textContainerHeightConstraint = NSLayoutConstraint(item: textContainer, attribute: .Height, relatedBy: .Equal, toItem: nil, attribute: .Height, multiplier: 1.0, constant: 0.0) + let textContainerWidthConstraint = NSLayoutConstraint(item: textContainer, attribute: .width, relatedBy: .equal, toItem: nil, attribute: .width, multiplier: 1.0, constant: innerContentWidth) + textContainerHeightConstraint = NSLayoutConstraint(item: textContainer, attribute: .height, relatedBy: .equal, toItem: nil, attribute: .height, multiplier: 1.0, constant: 0.0) textContainer.addConstraints([textContainerWidthConstraint, textContainerHeightConstraint]) // ButtonAreaScrollView - buttonAreaScrollViewHeightConstraint = NSLayoutConstraint(item: buttonAreaScrollView, attribute: .Height, relatedBy: .Equal, toItem: nil, attribute: .Height, multiplier: 1.0, constant: 0.0) - let buttonAreaViewTopSpaceConstraint = NSLayoutConstraint(item: buttonAreaView, attribute: .Top, relatedBy: .Equal, toItem: buttonAreaScrollView, attribute: .Top, multiplier: 1.0, constant: 0.0) - let buttonAreaViewRightSpaceConstraint = NSLayoutConstraint(item: buttonAreaView, attribute: .Right, relatedBy: .Equal, toItem: buttonAreaScrollView, attribute: .Right, multiplier: 1.0, constant: 0.0) - let buttonAreaViewLeftSpaceConstraint = NSLayoutConstraint(item: buttonAreaView, attribute: .Left, relatedBy: .Equal, toItem: buttonAreaScrollView, attribute: .Left, multiplier: 1.0, constant: 0.0) - let buttonAreaViewBottomSpaceConstraint = NSLayoutConstraint(item: buttonAreaView, attribute: .Bottom, relatedBy: .Equal, toItem: buttonAreaScrollView, attribute: .Bottom, multiplier: 1.0, constant: 0.0) - let buttonAreaViewWidthConstraint = NSLayoutConstraint(item: buttonAreaView, attribute: .Width, relatedBy: .Equal, toItem: buttonAreaScrollView, attribute: .Width, multiplier: 1.0, constant: 0.0) + buttonAreaScrollViewHeightConstraint = NSLayoutConstraint(item: buttonAreaScrollView, attribute: .height, relatedBy: .equal, toItem: nil, attribute: .height, multiplier: 1.0, constant: 0.0) + let buttonAreaViewTopSpaceConstraint = NSLayoutConstraint(item: buttonAreaView, attribute: .top, relatedBy: .equal, toItem: buttonAreaScrollView, attribute: .top, multiplier: 1.0, constant: 0.0) + let buttonAreaViewRightSpaceConstraint = NSLayoutConstraint(item: buttonAreaView, attribute: .right, relatedBy: .equal, toItem: buttonAreaScrollView, attribute: .right, multiplier: 1.0, constant: 0.0) + let buttonAreaViewLeftSpaceConstraint = NSLayoutConstraint(item: buttonAreaView, attribute: .left, relatedBy: .equal, toItem: buttonAreaScrollView, attribute: .left, multiplier: 1.0, constant: 0.0) + let buttonAreaViewBottomSpaceConstraint = NSLayoutConstraint(item: buttonAreaView, attribute: .bottom, relatedBy: .equal, toItem: buttonAreaScrollView, attribute: .bottom, multiplier: 1.0, constant: 0.0) + let buttonAreaViewWidthConstraint = NSLayoutConstraint(item: buttonAreaView, attribute: .width, relatedBy: .equal, toItem: buttonAreaScrollView, attribute: .width, multiplier: 1.0, constant: 0.0) buttonAreaScrollView.addConstraints([buttonAreaScrollViewHeightConstraint, buttonAreaViewTopSpaceConstraint, buttonAreaViewRightSpaceConstraint, buttonAreaViewLeftSpaceConstraint, buttonAreaViewBottomSpaceConstraint, buttonAreaViewWidthConstraint]) // ButtonArea - let buttonAreaViewHeightConstraint = NSLayoutConstraint(item: buttonAreaView, attribute: .Height, relatedBy: .Equal, toItem: buttonContainer, attribute: .Height, multiplier: 1.0, constant: 0.0) - let buttonContainerTopSpaceConstraint = NSLayoutConstraint(item: buttonContainer, attribute: .Top, relatedBy: .Equal, toItem: buttonAreaView, attribute: .Top, multiplier: 1.0, constant: 0.0) - let buttonContainerCenterXConstraint = NSLayoutConstraint(item: buttonContainer, attribute: .CenterX, relatedBy: .Equal, toItem: buttonAreaView, attribute: .CenterX, multiplier: 1.0, constant: 0.0) + let buttonAreaViewHeightConstraint = NSLayoutConstraint(item: buttonAreaView, attribute: .height, relatedBy: .equal, toItem: buttonContainer, attribute: .height, multiplier: 1.0, constant: 0.0) + let buttonContainerTopSpaceConstraint = NSLayoutConstraint(item: buttonContainer, attribute: .top, relatedBy: .equal, toItem: buttonAreaView, attribute: .top, multiplier: 1.0, constant: 0.0) + let buttonContainerCenterXConstraint = NSLayoutConstraint(item: buttonContainer, attribute: .centerX, relatedBy: .equal, toItem: buttonAreaView, attribute: .centerX, multiplier: 1.0, constant: 0.0) buttonAreaView.addConstraints([buttonAreaViewHeightConstraint, buttonContainerTopSpaceConstraint, buttonContainerCenterXConstraint]) // ButtonContainer - let buttonContainerWidthConstraint = NSLayoutConstraint(item: buttonContainer, attribute: .Width, relatedBy: .Equal, toItem: nil, attribute: .Width, multiplier: 1.0, constant: innerContentWidth) - buttonContainerHeightConstraint = NSLayoutConstraint(item: buttonContainer, attribute: .Height, relatedBy: .Equal, toItem: nil, attribute: .Height, multiplier: 1.0, constant: 0.0) + let buttonContainerWidthConstraint = NSLayoutConstraint(item: buttonContainer, attribute: .width, relatedBy: .equal, toItem: nil, attribute: .width, multiplier: 1.0, constant: innerContentWidth) + buttonContainerHeightConstraint = NSLayoutConstraint(item: buttonContainer, attribute: .height, relatedBy: .equal, toItem: nil, attribute: .height, multiplier: 1.0, constant: 0.0) buttonContainer.addConstraints([buttonContainerWidthConstraint, buttonContainerHeightConstraint]) } - public override init(nibName nibNameOrNil: String?, bundle nibBundleOrNil: NSBundle?) { + public override init(nibName nibNameOrNil: String?, bundle nibBundleOrNil: Bundle?) { super.init(nibName:nibNameOrNil, bundle:nibBundleOrNil) } @@ -413,21 +413,21 @@ public class DOAlertController : UIViewController, UITextFieldDelegate, UIViewCo fatalError("init(coder:) has not been implemented") } - public override func viewWillAppear(animated: Bool) { + open override func viewWillAppear(_ animated: Bool) { super.viewWillAppear(animated) layoutView() } - public override func viewDidAppear(animated: Bool) { + open override func viewDidAppear(_ animated: Bool) { super.viewDidAppear(animated) if (!isAlert() && cancelButtonTag != 0) { - let tapGesture = UITapGestureRecognizer(target: self, action: "handleContainerViewTapGesture:") + let tapGesture = UITapGestureRecognizer(target: self, action: #selector(DOAlertController.handleContainerViewTapGesture(_:))) containerView.addGestureRecognizer(tapGesture) } } - public func layoutView() { + open func layoutView() { if (layoutFlg) { return } layoutFlg = true @@ -449,28 +449,28 @@ public class DOAlertController : UIViewController, UITextFieldDelegate, UIViewCo // TitleLabel if (hasTitle) { - titleLabel.frame.size = CGSizeMake(innerContentWidth, 0.0) + titleLabel.frame.size = CGSize(width: innerContentWidth, height: 0.0) titleLabel.numberOfLines = 0 - titleLabel.textAlignment = .Center + titleLabel.textAlignment = .center titleLabel.font = titleFont titleLabel.textColor = titleTextColor titleLabel.text = title titleLabel.sizeToFit() - titleLabel.frame = CGRectMake(0, textAreaPositionY, innerContentWidth, titleLabel.frame.height) + titleLabel.frame = CGRect(x: 0, y: textAreaPositionY, width: innerContentWidth, height: titleLabel.frame.height) textContainer.addSubview(titleLabel) textAreaPositionY += titleLabel.frame.height + 5.0 } // MessageView if (hasMessage) { - messageView.frame.size = CGSizeMake(innerContentWidth, 0.0) + messageView.frame.size = CGSize(width: innerContentWidth, height: 0.0) messageView.numberOfLines = 0 - messageView.textAlignment = .Center + messageView.textAlignment = .center messageView.font = messageFont messageView.textColor = messageTextColor messageView.text = message messageView.sizeToFit() - messageView.frame = CGRectMake(0, textAreaPositionY, innerContentWidth, messageView.frame.height) + messageView.frame = CGRect(x: 0, y: textAreaPositionY, width: innerContentWidth, height: messageView.frame.height) textContainer.addSubview(messageView) textAreaPositionY += messageView.frame.height + 5.0 } @@ -483,20 +483,20 @@ public class DOAlertController : UIViewController, UITextFieldDelegate, UIViewCo textFieldContainerView.layer.masksToBounds = true textFieldContainerView.layer.cornerRadius = textFieldCornerRadius textFieldContainerView.layer.borderWidth = 0.5 - textFieldContainerView.layer.borderColor = textFieldBorderColor.CGColor + textFieldContainerView.layer.borderColor = textFieldBorderColor.cgColor textContainer.addSubview(textFieldContainerView) var textFieldContainerHeight: CGFloat = 0.0 // TextFields - for (i, obj) in (textFields!).enumerate() { + for (i, obj) in (textFields!).enumerated() { let textField = obj as! UITextField - textField.frame = CGRectMake(0.0, textFieldContainerHeight, innerContentWidth, textField.frame.height) + textField.frame = CGRect(x: 0.0, y: textFieldContainerHeight, width: innerContentWidth, height: textField.frame.height) textFieldContainerHeight += textField.frame.height + 0.5 } textFieldContainerHeight -= 0.5 - textFieldContainerView.frame = CGRectMake(0.0, textAreaPositionY, innerContentWidth, textFieldContainerHeight) + textFieldContainerView.frame = CGRect(x: 0.0, y: textAreaPositionY, width: innerContentWidth, height: textFieldContainerHeight) textAreaPositionY += textFieldContainerHeight + 5.0 } @@ -506,7 +506,7 @@ public class DOAlertController : UIViewController, UITextFieldDelegate, UIViewCo // TextAreaScrollView textAreaHeight = textAreaPositionY - textAreaScrollView.contentSize = CGSizeMake(alertViewWidth, textAreaHeight) + textAreaScrollView.contentSize = CGSize(width: alertViewWidth, height: textAreaHeight) textContainerHeightConstraint.constant = textAreaHeight //------------------------------ @@ -520,25 +520,25 @@ public class DOAlertController : UIViewController, UITextFieldDelegate, UIViewCo var buttonPositionX: CGFloat = 0.0 for button in buttons { let action = actions[button.tag - 1] as! DOAlertAction - button.titleLabel?.font = buttonFont[action.style] - button.setTitleColor(buttonTextColor[action.style], forState: .Normal) - button.setBackgroundImage(createImageFromUIColor(buttonBgColor[action.style]!), forState: .Normal) - button.setBackgroundImage(createImageFromUIColor(buttonBgColorHighlighted[action.style]!), forState: .Highlighted) - button.setBackgroundImage(createImageFromUIColor(buttonBgColorHighlighted[action.style]!), forState: .Selected) - button.frame = CGRectMake(buttonPositionX, buttonAreaPositionY, buttonWidth, buttonHeight) + button.titleLabel?.font = buttonFont[action.style]! + button.setTitleColor(buttonTextColor[action.style], for: UIControlState()) + button.setBackgroundImage(createImageFromUIColor(buttonBgColor[action.style]!), for: UIControlState()) + button.setBackgroundImage(createImageFromUIColor(buttonBgColorHighlighted[action.style]!), for: .highlighted) + button.setBackgroundImage(createImageFromUIColor(buttonBgColorHighlighted[action.style]!), for: .selected) + button.frame = CGRect(x: buttonPositionX, y: buttonAreaPositionY, width: buttonWidth, height: buttonHeight) buttonPositionX += buttonMargin + buttonWidth } buttonAreaPositionY += buttonHeight } else { for button in buttons { let action = actions[button.tag - 1] as! DOAlertAction - if (action.style != DOAlertActionStyle.Cancel) { - button.titleLabel?.font = buttonFont[action.style] - button.setTitleColor(buttonTextColor[action.style], forState: .Normal) - button.setBackgroundImage(createImageFromUIColor(buttonBgColor[action.style]!), forState: .Normal) - button.setBackgroundImage(createImageFromUIColor(buttonBgColorHighlighted[action.style]!), forState: .Highlighted) - button.setBackgroundImage(createImageFromUIColor(buttonBgColorHighlighted[action.style]!), forState: .Selected) - button.frame = CGRectMake(0, buttonAreaPositionY, innerContentWidth, buttonHeight) + if (action.style != DOAlertActionStyle.cancel) { + button.titleLabel?.font = buttonFont[action.style]! + button.setTitleColor(buttonTextColor[action.style], for: UIControlState()) + button.setBackgroundImage(createImageFromUIColor(buttonBgColor[action.style]!), for: UIControlState()) + button.setBackgroundImage(createImageFromUIColor(buttonBgColorHighlighted[action.style]!), for: .highlighted) + button.setBackgroundImage(createImageFromUIColor(buttonBgColorHighlighted[action.style]!), for: .selected) + button.frame = CGRect(x: 0, y: buttonAreaPositionY, width: innerContentWidth, height: buttonHeight) buttonAreaPositionY += buttonHeight + buttonMargin } else { cancelButtonTag = button.tag @@ -552,12 +552,12 @@ public class DOAlertController : UIViewController, UITextFieldDelegate, UIViewCo } let button = buttonAreaScrollView.viewWithTag(cancelButtonTag) as! UIButton let action = actions[cancelButtonTag - 1] as! DOAlertAction - button.titleLabel?.font = buttonFont[action.style] - button.setTitleColor(buttonTextColor[action.style], forState: .Normal) - button.setBackgroundImage(createImageFromUIColor(buttonBgColor[action.style]!), forState: .Normal) - button.setBackgroundImage(createImageFromUIColor(buttonBgColorHighlighted[action.style]!), forState: .Highlighted) - button.setBackgroundImage(createImageFromUIColor(buttonBgColorHighlighted[action.style]!), forState: .Selected) - button.frame = CGRectMake(0, buttonAreaPositionY, innerContentWidth, buttonHeight) + button.titleLabel?.font = buttonFont[action.style]! + button.setTitleColor(buttonTextColor[action.style], for: UIControlState()) + button.setBackgroundImage(createImageFromUIColor(buttonBgColor[action.style]!), for: UIControlState()) + button.setBackgroundImage(createImageFromUIColor(buttonBgColorHighlighted[action.style]!), for: .highlighted) + button.setBackgroundImage(createImageFromUIColor(buttonBgColorHighlighted[action.style]!), for: .selected) + button.frame = CGRect(x: 0, y: buttonAreaPositionY, width: innerContentWidth, height: buttonHeight) buttonAreaPositionY += buttonHeight + buttonMargin } buttonAreaPositionY -= buttonMargin @@ -570,7 +570,7 @@ public class DOAlertController : UIViewController, UITextFieldDelegate, UIViewCo // ButtonAreaScrollView Height buttonAreaHeight = buttonAreaPositionY - buttonAreaScrollView.contentSize = CGSizeMake(alertViewWidth, buttonAreaHeight) + buttonAreaScrollView.contentSize = CGSize(width: alertViewWidth, height: buttonAreaHeight) buttonContainerHeightConstraint.constant = buttonAreaHeight //------------------------------ @@ -578,16 +578,16 @@ public class DOAlertController : UIViewController, UITextFieldDelegate, UIViewCo //------------------------------ // AlertView Height reloadAlertViewHeight() - alertView.frame.size = CGSizeMake(alertViewWidth, alertViewHeightConstraint.constant) + alertView.frame.size = CGSize(width: alertViewWidth, height: alertViewHeightConstraint.constant) } // Reload AlertView Height - public func reloadAlertViewHeight() { + open func reloadAlertViewHeight() { - var screenSize = UIScreen.mainScreen().bounds.size - if ((UIDevice.currentDevice().systemVersion as NSString).floatValue < 8.0) { - if (UIInterfaceOrientationIsLandscape(UIApplication.sharedApplication().statusBarOrientation)) { - screenSize = CGSizeMake(screenSize.height, screenSize.width) + var screenSize = UIScreen.main.bounds.size + if ((UIDevice.current.systemVersion as NSString).floatValue < 8.0) { + if (UIInterfaceOrientationIsLandscape(UIApplication.shared.statusBarOrientation)) { + screenSize = CGSize(width: screenSize.height, height: screenSize.width) } } let maxHeight = screenSize.height - keyboardHeight @@ -614,67 +614,67 @@ public class DOAlertController : UIViewController, UITextFieldDelegate, UIViewCo } // Button Tapped Action - public func buttonTapped(sender: UIButton) { - sender.selected = true + open func buttonTapped(_ sender: UIButton) { + sender.isSelected = true let action = actions[sender.tag - 1] as! DOAlertAction if (action.handler != nil) { action.handler(action) } - self.dismissViewControllerAnimated(true, completion: nil) + self.dismiss(animated: true, completion: nil) } // Handle ContainerView tap gesture - public func handleContainerViewTapGesture(sender: AnyObject) { + open func handleContainerViewTapGesture(_ sender: AnyObject) { // cancel action let action = actions[cancelButtonTag - 1] as! DOAlertAction if (action.handler != nil) { action.handler(action) } - self.dismissViewControllerAnimated(true, completion: nil) + self.dismiss(animated: true, completion: nil) } // UIColor -> UIImage - public func createImageFromUIColor(color: UIColor) -> UIImage { - let rect = CGRectMake(0, 0, 1, 1) + open func createImageFromUIColor(_ color: UIColor) -> UIImage { + let rect = CGRect(x: 0, y: 0, width: 1, height: 1) UIGraphicsBeginImageContext(rect.size) - let contextRef: CGContextRef = UIGraphicsGetCurrentContext()! - CGContextSetFillColorWithColor(contextRef, color.CGColor) - CGContextFillRect(contextRef, rect) - let img: UIImage = UIGraphicsGetImageFromCurrentImageContext() + let contextRef: CGContext = UIGraphicsGetCurrentContext()! + contextRef.setFillColor(color.cgColor) + contextRef.fill(rect) + let img: UIImage = UIGraphicsGetImageFromCurrentImageContext()! UIGraphicsEndImageContext() return img } // MARK : Handle NSNotification Method - @objc public func handleAlertActionEnabledDidChangeNotification(notification: NSNotification) { + @objc open func handleAlertActionEnabledDidChangeNotification(_ notification: Notification) { for i in 0.. Void)!) { + open func addTextFieldWithConfigurationHandler(_ configurationHandler: ((UITextField?) -> Void)!) { // You can add a text field only if the preferredStyle property is set to DOAlertControllerStyle.Alert. if (!isAlert()) { - NSException.raise("NSInternalInconsistencyException", format: "Text fields can only be added to an alert controller of style DOAlertControllerStyleAlert", arguments:getVaList(["nil"])) + NSException.raise(NSExceptionName(rawValue: "NSInternalInconsistencyException"), format: "Text fields can only be added to an alert controller of style DOAlertControllerStyleAlert", arguments:getVaList(["nil"])) return } if (textFields == nil) { @@ -721,8 +721,8 @@ public class DOAlertController : UIViewController, UITextFieldDelegate, UIViewCo } let textField = UITextField() - textField.frame.size = CGSizeMake(innerContentWidth, textFieldHeight) - textField.borderStyle = UITextBorderStyle.None + textField.frame.size = CGSize(width: innerContentWidth, height: textFieldHeight) + textField.borderStyle = UITextBorderStyle.none textField.backgroundColor = textFieldBgColor textField.delegate = self @@ -734,26 +734,26 @@ public class DOAlertController : UIViewController, UITextFieldDelegate, UIViewCo textFieldContainerView.addSubview(textField) } - public func isAlert() -> Bool { return preferredStyle == .Alert } + open func isAlert() -> Bool { return preferredStyle == .alert } // MARK: UITextFieldDelegate Methods - public func textFieldShouldReturn(textField: UITextField) -> Bool { - if (textField.canResignFirstResponder()) { + open func textFieldShouldReturn(_ textField: UITextField) -> Bool { + if (textField.canResignFirstResponder) { textField.resignFirstResponder() - self.dismissViewControllerAnimated(true, completion: nil) + self.dismiss(animated: true, completion: nil) } return true } // MARK: UIViewControllerTransitioningDelegate Methods - public func animationControllerForPresentedController(presented: UIViewController, presentingController presenting: UIViewController, sourceController source: UIViewController) -> UIViewControllerAnimatedTransitioning? { + open func animationController(forPresented presented: UIViewController, presenting: UIViewController, source: UIViewController) -> UIViewControllerAnimatedTransitioning? { layoutView() return DOAlertAnimation(isPresenting: true) } - public func animationControllerForDismissedController(dismissed: UIViewController) -> UIViewControllerAnimatedTransitioning? { + open func animationController(forDismissed dismissed: UIViewController) -> UIViewControllerAnimatedTransitioning? { return DOAlertAnimation(isPresenting: false) } } From e4cb3d780ecb6aaad78b1a9d4af991443f6693cb Mon Sep 17 00:00:00 2001 From: Nicolas Klein Date: Wed, 19 Jul 2017 10:36:03 +0200 Subject: [PATCH 06/11] adds gitignore --- .gitignore | 1 + 1 file changed, 1 insertion(+) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..9bce6af --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +xcuserdata From 8031fcee502c9463ffa9d84c773f8f3a602a86f8 Mon Sep 17 00:00:00 2001 From: Nicolas Klein Date: Wed, 19 Jul 2017 10:36:37 +0200 Subject: [PATCH 07/11] adds project file with shared scheme to make it usable with carthage --- DOAlertController.xcodeproj/project.pbxproj | 303 ++++++++++++++++++ .../contents.xcworkspacedata | 7 + .../xcschemes/DOAlertController.xcscheme | 80 +++++ 3 files changed, 390 insertions(+) create mode 100644 DOAlertController.xcodeproj/project.pbxproj create mode 100644 DOAlertController.xcodeproj/project.xcworkspace/contents.xcworkspacedata create mode 100644 DOAlertController.xcodeproj/xcshareddata/xcschemes/DOAlertController.xcscheme diff --git a/DOAlertController.xcodeproj/project.pbxproj b/DOAlertController.xcodeproj/project.pbxproj new file mode 100644 index 0000000..8099d60 --- /dev/null +++ b/DOAlertController.xcodeproj/project.pbxproj @@ -0,0 +1,303 @@ +// !$*UTF8*$! +{ + archiveVersion = 1; + classes = { + }; + objectVersion = 46; + objects = { + +/* Begin PBXBuildFile section */ + DB99509D1F1F50C40061E80C /* DOAlertController.swift in Sources */ = {isa = PBXBuildFile; fileRef = DB99509C1F1F50C40061E80C /* DOAlertController.swift */; }; +/* End PBXBuildFile section */ + +/* Begin PBXFileReference section */ + DB9950911F1F50890061E80C /* DOAlertController.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = DOAlertController.framework; sourceTree = BUILT_PRODUCTS_DIR; }; + DB99509C1F1F50C40061E80C /* DOAlertController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DOAlertController.swift; sourceTree = ""; }; +/* End PBXFileReference section */ + +/* Begin PBXFrameworksBuildPhase section */ + DB99508D1F1F50890061E80C /* Frameworks */ = { + isa = PBXFrameworksBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXFrameworksBuildPhase section */ + +/* Begin PBXGroup section */ + DB9950871F1F50890061E80C = { + isa = PBXGroup; + children = ( + DB9950931F1F50890061E80C /* DOAlertController */, + DB9950921F1F50890061E80C /* Products */, + ); + sourceTree = ""; + }; + DB9950921F1F50890061E80C /* Products */ = { + isa = PBXGroup; + children = ( + DB9950911F1F50890061E80C /* DOAlertController.framework */, + ); + name = Products; + sourceTree = ""; + }; + DB9950931F1F50890061E80C /* DOAlertController */ = { + isa = PBXGroup; + children = ( + DB99509C1F1F50C40061E80C /* DOAlertController.swift */, + ); + path = DOAlertController; + sourceTree = ""; + }; +/* End PBXGroup section */ + +/* Begin PBXHeadersBuildPhase section */ + DB99508E1F1F50890061E80C /* Headers */ = { + isa = PBXHeadersBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXHeadersBuildPhase section */ + +/* Begin PBXNativeTarget section */ + DB9950901F1F50890061E80C /* DOAlertController */ = { + isa = PBXNativeTarget; + buildConfigurationList = DB9950991F1F50890061E80C /* Build configuration list for PBXNativeTarget "DOAlertController" */; + buildPhases = ( + DB99508C1F1F50890061E80C /* Sources */, + DB99508D1F1F50890061E80C /* Frameworks */, + DB99508E1F1F50890061E80C /* Headers */, + DB99508F1F1F50890061E80C /* Resources */, + ); + buildRules = ( + ); + dependencies = ( + ); + name = DOAlertController; + productName = DOAlertController; + productReference = DB9950911F1F50890061E80C /* DOAlertController.framework */; + productType = "com.apple.product-type.framework"; + }; +/* End PBXNativeTarget section */ + +/* Begin PBXProject section */ + DB9950881F1F50890061E80C /* Project object */ = { + isa = PBXProject; + attributes = { + LastUpgradeCheck = 0830; + ORGANIZATIONNAME = "okmr-d"; + TargetAttributes = { + DB9950901F1F50890061E80C = { + CreatedOnToolsVersion = 8.3.3; + LastSwiftMigration = 0830; + ProvisioningStyle = Automatic; + }; + }; + }; + buildConfigurationList = DB99508B1F1F50890061E80C /* Build configuration list for PBXProject "DOAlertController" */; + compatibilityVersion = "Xcode 3.2"; + developmentRegion = English; + hasScannedForEncodings = 0; + knownRegions = ( + en, + ); + mainGroup = DB9950871F1F50890061E80C; + productRefGroup = DB9950921F1F50890061E80C /* Products */; + projectDirPath = ""; + projectRoot = ""; + targets = ( + DB9950901F1F50890061E80C /* DOAlertController */, + ); + }; +/* End PBXProject section */ + +/* Begin PBXResourcesBuildPhase section */ + DB99508F1F1F50890061E80C /* Resources */ = { + isa = PBXResourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXResourcesBuildPhase section */ + +/* Begin PBXSourcesBuildPhase section */ + DB99508C1F1F50890061E80C /* Sources */ = { + isa = PBXSourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + DB99509D1F1F50C40061E80C /* DOAlertController.swift in Sources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXSourcesBuildPhase section */ + +/* Begin XCBuildConfiguration section */ + DB9950971F1F50890061E80C /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; + CLANG_ANALYZER_NONNULL = YES; + CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; + CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; + CLANG_CXX_LIBRARY = "libc++"; + CLANG_ENABLE_MODULES = YES; + CLANG_ENABLE_OBJC_ARC = YES; + CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; + CLANG_WARN_DOCUMENTATION_COMMENTS = YES; + CLANG_WARN_EMPTY_BODY = YES; + CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INFINITE_RECURSION = YES; + CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_SUSPICIOUS_MOVE = YES; + CLANG_WARN_UNREACHABLE_CODE = YES; + CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; + "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; + COPY_PHASE_STRIP = NO; + CURRENT_PROJECT_VERSION = 1; + DEBUG_INFORMATION_FORMAT = dwarf; + ENABLE_STRICT_OBJC_MSGSEND = YES; + ENABLE_TESTABILITY = YES; + GCC_C_LANGUAGE_STANDARD = gnu99; + GCC_DYNAMIC_NO_PIC = NO; + GCC_NO_COMMON_BLOCKS = YES; + GCC_OPTIMIZATION_LEVEL = 0; + GCC_PREPROCESSOR_DEFINITIONS = ( + "DEBUG=1", + "$(inherited)", + ); + GCC_WARN_64_TO_32_BIT_CONVERSION = YES; + GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; + GCC_WARN_UNDECLARED_SELECTOR = YES; + GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; + GCC_WARN_UNUSED_FUNCTION = YES; + GCC_WARN_UNUSED_VARIABLE = YES; + IPHONEOS_DEPLOYMENT_TARGET = 10.3; + MTL_ENABLE_DEBUG_INFO = YES; + ONLY_ACTIVE_ARCH = YES; + SDKROOT = iphoneos; + SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG; + SWIFT_OPTIMIZATION_LEVEL = "-Onone"; + TARGETED_DEVICE_FAMILY = "1,2"; + VERSIONING_SYSTEM = "apple-generic"; + VERSION_INFO_PREFIX = ""; + }; + name = Debug; + }; + DB9950981F1F50890061E80C /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; + CLANG_ANALYZER_NONNULL = YES; + CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; + CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; + CLANG_CXX_LIBRARY = "libc++"; + CLANG_ENABLE_MODULES = YES; + CLANG_ENABLE_OBJC_ARC = YES; + CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; + CLANG_WARN_DOCUMENTATION_COMMENTS = YES; + CLANG_WARN_EMPTY_BODY = YES; + CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INFINITE_RECURSION = YES; + CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_SUSPICIOUS_MOVE = YES; + CLANG_WARN_UNREACHABLE_CODE = YES; + CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; + "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; + COPY_PHASE_STRIP = NO; + CURRENT_PROJECT_VERSION = 1; + DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; + ENABLE_NS_ASSERTIONS = NO; + ENABLE_STRICT_OBJC_MSGSEND = YES; + GCC_C_LANGUAGE_STANDARD = gnu99; + GCC_NO_COMMON_BLOCKS = YES; + GCC_WARN_64_TO_32_BIT_CONVERSION = YES; + GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; + GCC_WARN_UNDECLARED_SELECTOR = YES; + GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; + GCC_WARN_UNUSED_FUNCTION = YES; + GCC_WARN_UNUSED_VARIABLE = YES; + IPHONEOS_DEPLOYMENT_TARGET = 10.3; + MTL_ENABLE_DEBUG_INFO = NO; + SDKROOT = iphoneos; + SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; + TARGETED_DEVICE_FAMILY = "1,2"; + VALIDATE_PRODUCT = YES; + VERSIONING_SYSTEM = "apple-generic"; + VERSION_INFO_PREFIX = ""; + }; + name = Release; + }; + DB99509A1F1F50890061E80C /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + CLANG_ENABLE_MODULES = YES; + CODE_SIGN_IDENTITY = ""; + DEFINES_MODULE = YES; + DYLIB_COMPATIBILITY_VERSION = 1; + DYLIB_CURRENT_VERSION = 1; + DYLIB_INSTALL_NAME_BASE = "@rpath"; + INFOPLIST_FILE = DOAlertController/Info.plist; + INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; + LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; + PRODUCT_BUNDLE_IDENTIFIER = co.devlog.DOAlertController; + PRODUCT_NAME = "$(TARGET_NAME)"; + SKIP_INSTALL = YES; + SWIFT_OPTIMIZATION_LEVEL = "-Onone"; + SWIFT_VERSION = 3.0; + }; + name = Debug; + }; + DB99509B1F1F50890061E80C /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + CLANG_ENABLE_MODULES = YES; + CODE_SIGN_IDENTITY = ""; + DEFINES_MODULE = YES; + DYLIB_COMPATIBILITY_VERSION = 1; + DYLIB_CURRENT_VERSION = 1; + DYLIB_INSTALL_NAME_BASE = "@rpath"; + INFOPLIST_FILE = DOAlertController/Info.plist; + INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; + LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; + PRODUCT_BUNDLE_IDENTIFIER = co.devlog.DOAlertController; + PRODUCT_NAME = "$(TARGET_NAME)"; + SKIP_INSTALL = YES; + SWIFT_VERSION = 3.0; + }; + name = Release; + }; +/* End XCBuildConfiguration section */ + +/* Begin XCConfigurationList section */ + DB99508B1F1F50890061E80C /* Build configuration list for PBXProject "DOAlertController" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + DB9950971F1F50890061E80C /* Debug */, + DB9950981F1F50890061E80C /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; + DB9950991F1F50890061E80C /* Build configuration list for PBXNativeTarget "DOAlertController" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + DB99509A1F1F50890061E80C /* Debug */, + DB99509B1F1F50890061E80C /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; +/* End XCConfigurationList section */ + }; + rootObject = DB9950881F1F50890061E80C /* Project object */; +} diff --git a/DOAlertController.xcodeproj/project.xcworkspace/contents.xcworkspacedata b/DOAlertController.xcodeproj/project.xcworkspace/contents.xcworkspacedata new file mode 100644 index 0000000..31e65c5 --- /dev/null +++ b/DOAlertController.xcodeproj/project.xcworkspace/contents.xcworkspacedata @@ -0,0 +1,7 @@ + + + + + diff --git a/DOAlertController.xcodeproj/xcshareddata/xcschemes/DOAlertController.xcscheme b/DOAlertController.xcodeproj/xcshareddata/xcschemes/DOAlertController.xcscheme new file mode 100644 index 0000000..0abb180 --- /dev/null +++ b/DOAlertController.xcodeproj/xcshareddata/xcschemes/DOAlertController.xcscheme @@ -0,0 +1,80 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + From 93fd723cd7d575c71b3657bab281699662767548 Mon Sep 17 00:00:00 2001 From: Nicolas Klein Date: Wed, 19 Jul 2017 11:17:26 +0200 Subject: [PATCH 08/11] revert to origin code --- DOAlertController/DOAlertController.swift | 300 +++++++++++----------- 1 file changed, 151 insertions(+), 149 deletions(-) diff --git a/DOAlertController/DOAlertController.swift b/DOAlertController/DOAlertController.swift index 4bad979..37234a7 100644 --- a/DOAlertController/DOAlertController.swift +++ b/DOAlertController/DOAlertController.swift @@ -30,7 +30,7 @@ public enum DOAlertControllerStyle : Int { open class DOAlertAction : NSObject, NSCopying { open var title: String open var style: DOAlertActionStyle - open var handler: ((DOAlertAction?) -> Void)! + var handler: ((DOAlertAction?) -> Void)! open var enabled: Bool { didSet { if (oldValue != enabled) { @@ -45,7 +45,7 @@ open class DOAlertAction : NSObject, NSCopying { self.handler = handler self.enabled = true } - + open func copy(with zone: NSZone?) -> Any { let copy = type(of: self).init(title: title, style: style, handler: handler) copy.enabled = self.enabled @@ -57,12 +57,12 @@ open class DOAlertAction : NSObject, NSCopying { open class DOAlertAnimation : NSObject, UIViewControllerAnimatedTransitioning { - open let isPresenting: Bool - - public init(isPresenting: Bool) { + let isPresenting: Bool + + init(isPresenting: Bool) { self.isPresenting = isPresenting } - + open func transitionDuration(using transitionContext: UIViewControllerContextTransitioning?) -> TimeInterval { if (isPresenting) { return 0.45 @@ -70,7 +70,7 @@ open class DOAlertAnimation : NSObject, UIViewControllerAnimatedTransitioning { return 0.25 } } - + open func animateTransition(using transitionContext: UIViewControllerContextTransitioning) { if (isPresenting) { self.presentAnimateTransition(transitionContext) @@ -79,11 +79,11 @@ open class DOAlertAnimation : NSObject, UIViewControllerAnimatedTransitioning { } } - open func presentAnimateTransition(_ transitionContext: UIViewControllerContextTransitioning) { - + func presentAnimateTransition(_ transitionContext: UIViewControllerContextTransitioning) { + let alertController = transitionContext.viewController(forKey: UITransitionContextViewControllerKey.to) as! DOAlertController let containerView = transitionContext.containerView - + alertController.overlayView.alpha = 0.0 if (alertController.isAlert()) { alertController.alertView.alpha = 0.0 @@ -93,47 +93,47 @@ open class DOAlertAnimation : NSObject, UIViewControllerAnimatedTransitioning { alertController.alertView.transform = CGAffineTransform(translationX: 0, y: alertController.alertView.frame.height) } containerView.addSubview(alertController.view) - + UIView.animate(withDuration: 0.25, - animations: { - alertController.overlayView.alpha = 1.0 - if (alertController.isAlert()) { - alertController.alertView.alpha = 1.0 - alertController.alertView.transform = CGAffineTransform(scaleX: 1.05, y: 1.05) - } else { - let bounce = alertController.alertView.frame.height / 480 * 10.0 + 10.0 - alertController.alertView.transform = CGAffineTransform(translationX: 0, y: -bounce) - } + animations: { + alertController.overlayView.alpha = 1.0 + if (alertController.isAlert()) { + alertController.alertView.alpha = 1.0 + alertController.alertView.transform = CGAffineTransform(scaleX: 1.05, y: 1.05) + } else { + let bounce = alertController.alertView.frame.height / 480 * 10.0 + 10.0 + alertController.alertView.transform = CGAffineTransform(translationX: 0, y: -bounce) + } }, - completion: { finished in - UIView.animate(withDuration: 0.2, - animations: { - alertController.alertView.transform = CGAffineTransform.identity - }, - completion: { finished in - if (finished) { - transitionContext.completeTransition(true) - } - }) + completion: { finished in + UIView.animate(withDuration: 0.2, + animations: { + alertController.alertView.transform = CGAffineTransform.identity + }, + completion: { finished in + if (finished) { + transitionContext.completeTransition(true) + } + }) }) } - - open func dismissAnimateTransition(_ transitionContext: UIViewControllerContextTransitioning) { - + + func dismissAnimateTransition(_ transitionContext: UIViewControllerContextTransitioning) { + let alertController = transitionContext.viewController(forKey: UITransitionContextViewControllerKey.from) as! DOAlertController - + UIView.animate(withDuration: self.transitionDuration(using: transitionContext), - animations: { - alertController.overlayView.alpha = 0.0 - if (alertController.isAlert()) { - alertController.alertView.alpha = 0.0 - alertController.alertView.transform = CGAffineTransform(scaleX: 0.9, y: 0.9) - } else { - alertController.containerView.transform = CGAffineTransform(translationX: 0, y: alertController.alertView.frame.height) - } + animations: { + alertController.overlayView.alpha = 0.0 + if (alertController.isAlert()) { + alertController.alertView.alpha = 0.0 + alertController.alertView.transform = CGAffineTransform(scaleX: 0.9, y: 0.9) + } else { + alertController.containerView.transform = CGAffineTransform(translationX: 0, y: alertController.alertView.frame.height) + } }, - completion: { finished in - transitionContext.completeTransition(true) + completion: { finished in + transitionContext.completeTransition(true) }) } } @@ -141,21 +141,21 @@ open class DOAlertAnimation : NSObject, UIViewControllerAnimatedTransitioning { // MARK: DOAlertController Class @objc(DOAlertController) open class DOAlertController : UIViewController, UITextFieldDelegate, UIViewControllerTransitioningDelegate { - + // Message open var message: String? - + // AlertController Style fileprivate(set) var preferredStyle: DOAlertControllerStyle? - + // OverlayView fileprivate var overlayView = UIView() open var overlayColor = UIColor(red:0, green:0, blue:0, alpha:0.5) - + // ContainerView - fileprivate(set) open var containerView = UIView() + fileprivate var containerView = UIView() fileprivate var containerViewBottomSpaceConstraint: NSLayoutConstraint? - + // AlertView open var alertView = UIView() open var alertViewBgColor = UIColor(red:239/255, green:240/255, blue:242/255, alpha:1.0) @@ -164,55 +164,55 @@ open class DOAlertController : UIViewController, UITextFieldDelegate, UIViewCont fileprivate var alertViewPadding: CGFloat = 15.0 fileprivate var innerContentWidth: CGFloat = 240.0 fileprivate let actionSheetBounceHeight: CGFloat = 20.0 - + // TextAreaScrollView fileprivate var textAreaScrollView = UIScrollView() fileprivate var textAreaHeight: CGFloat = 0.0 - + // TextAreaView fileprivate var textAreaView = UIView() - + // TextContainer fileprivate var textContainer = UIView() fileprivate var textContainerHeightConstraint: NSLayoutConstraint? - + // TitleLabel open var titleLabel = UILabel() open var titleFont = UIFont(name: "HelveticaNeue-Bold", size: 18) open var titleTextColor = UIColor(red:77/255, green:77/255, blue:77/255, alpha:1.0) - + // MessageView open var messageView = UILabel() open var messageFont = UIFont(name: "HelveticaNeue", size: 15) open var messageTextColor = UIColor(red:77/255, green:77/255, blue:77/255, alpha:1.0) - + // TextFieldContainerView open var textFieldContainerView = UIView() open var textFieldBorderColor = UIColor(red: 203.0/255, green: 203.0/255, blue: 203.0/255, alpha: 1.0) - + // TextFields fileprivate(set) var textFields: [AnyObject]? fileprivate let textFieldHeight: CGFloat = 30.0 open var textFieldBgColor = UIColor.white fileprivate let textFieldCornerRadius: CGFloat = 4.0 - + // ButtonAreaScrollView fileprivate var buttonAreaScrollView = UIScrollView() fileprivate var buttonAreaScrollViewHeightConstraint: NSLayoutConstraint? fileprivate var buttonAreaHeight: CGFloat = 0.0 - + // ButtonAreaView fileprivate var buttonAreaView = UIView() - + // ButtonContainer fileprivate var buttonContainer = UIView() fileprivate var buttonContainerHeightConstraint: NSLayoutConstraint? fileprivate let buttonHeight: CGFloat = 44.0 fileprivate var buttonMargin: CGFloat = 10.0 - + // Actions open fileprivate(set) var actions: [AnyObject] = [] - + // Buttons open var buttons = [UIButton]() open var buttonFont: [DOAlertActionStyle : UIFont] = [ @@ -236,71 +236,71 @@ open class DOAlertController : UIViewController, UITextFieldDelegate, UIViewCont .destructive : UIColor(red:234/255, green:97/255, blue:83/255, alpha:1) ] fileprivate var buttonCornerRadius: CGFloat = 4.0 - + fileprivate var layoutFlg = false fileprivate var keyboardHeight: CGFloat = 0.0 fileprivate var cancelButtonTag = 0 - + // Initializer public convenience init(title: String?, message: String?, preferredStyle: DOAlertControllerStyle) { self.init(nibName: nil, bundle: nil) - + self.title = title self.message = message self.preferredStyle = preferredStyle - + self.providesPresentationContextTransitionStyle = true self.definesPresentationContext = true self.modalPresentationStyle = UIModalPresentationStyle.custom - + // NotificationCenter NotificationCenter.default.addObserver(self, selector: #selector(DOAlertController.handleAlertActionEnabledDidChangeNotification(_:)), name: NSNotification.Name(rawValue: DOAlertActionEnabledDidChangeNotification), object: nil) NotificationCenter.default.addObserver(self, selector: #selector(DOAlertController.handleKeyboardWillShowNotification(_:)), name: NSNotification.Name.UIKeyboardWillShow, object: nil) NotificationCenter.default.addObserver(self, selector: #selector(DOAlertController.handleKeyboardWillHideNotification(_:)), name: NSNotification.Name.UIKeyboardWillHide, object: nil) - + // Delegate self.transitioningDelegate = self } - + deinit { NotificationCenter.default.removeObserver(self) } - + override public init(nibName nibNameOrNil: String?, bundle nibBundleOrNil: Bundle?) { super.init(nibName:nibNameOrNil, bundle:nibBundleOrNil) } - + required public init?(coder aDecoder: NSCoder) { fatalError("init(coder:) has not been implemented") } - + func currentOrientation() -> UIInterfaceOrientation { return UIScreen.main.bounds.size.width < UIScreen.main.bounds.size.height ? .portrait : .landscapeLeft } - + override open func viewWillAppear(_ animated: Bool) { super.viewWillAppear(animated) } - + override open func viewDidAppear(_ animated: Bool) { super.viewDidAppear(animated) - + if (!isAlert() && cancelButtonTag != 0) { let tapGesture = UITapGestureRecognizer(target: self, action: #selector(DOAlertController.handleContainerViewTapGesture(_:))) containerView.addGestureRecognizer(tapGesture) } } - + open override func viewWillLayoutSubviews() { super.viewWillLayoutSubviews() layoutView(self.presentingViewController) } - - + + open func layoutView(_ presenting: UIViewController?) { if (layoutFlg) { return } layoutFlg = true - + // Screen Size var screenSize = presenting != nil ? presenting!.view.bounds.size : UIScreen.main.bounds.size if ((UIDevice.current.systemVersion as NSString).floatValue < 8.0) { @@ -308,7 +308,7 @@ open class DOAlertController : UIViewController, UITextFieldDelegate, UIViewCont screenSize = CGSize(width: screenSize.height, height: screenSize.width) } } - + // variable for ActionSheet if (!isAlert()) { alertViewWidth = screenSize.width @@ -317,37 +317,37 @@ open class DOAlertController : UIViewController, UITextFieldDelegate, UIViewCont buttonMargin = 8.0 buttonCornerRadius = 6.0 } - + // self.view self.view.frame.size = screenSize - + // OverlayView self.view.addSubview(overlayView) - + // ContainerView self.view.addSubview(containerView) - + // AlertView containerView.addSubview(alertView) - + // TextAreaScrollView alertView.addSubview(textAreaScrollView) - + // TextAreaView textAreaScrollView.addSubview(textAreaView) - + // TextContainer textAreaView.addSubview(textContainer) - + // ButtonAreaScrollView alertView.addSubview(buttonAreaScrollView) - + // ButtonAreaView buttonAreaScrollView.addSubview(buttonAreaView) - + // ButtonContainer buttonAreaView.addSubview(buttonContainer) - + //------------------------------ // Layout Constraint //------------------------------ @@ -360,7 +360,7 @@ open class DOAlertController : UIViewController, UITextFieldDelegate, UIViewCont buttonAreaScrollView.translatesAutoresizingMaskIntoConstraints = false buttonAreaView.translatesAutoresizingMaskIntoConstraints = false buttonContainer.translatesAutoresizingMaskIntoConstraints = false - + // self.view let overlayViewTopSpaceConstraint = NSLayoutConstraint(item: overlayView, attribute: .top, relatedBy: .equal, toItem: self.view, attribute: .top, multiplier: 1.0, constant: 0.0) let overlayViewRightSpaceConstraint = NSLayoutConstraint(item: overlayView, attribute: .right, relatedBy: .equal, toItem: self.view, attribute: .right, multiplier: 1.0, constant: 0.0) @@ -371,30 +371,30 @@ open class DOAlertController : UIViewController, UITextFieldDelegate, UIViewCont let containerViewLeftSpaceConstraint = NSLayoutConstraint(item: containerView, attribute: .left, relatedBy: .equal, toItem: self.view, attribute: .left, multiplier: 1.0, constant: 0.0) containerViewBottomSpaceConstraint = NSLayoutConstraint(item: containerView, attribute: .bottom, relatedBy: .equal, toItem: self.view, attribute: .bottom, multiplier: 1.0, constant: 0.0) self.view.addConstraints([overlayViewTopSpaceConstraint, overlayViewRightSpaceConstraint, overlayViewLeftSpaceConstraint, overlayViewBottomSpaceConstraint, containerViewTopSpaceConstraint, containerViewRightSpaceConstraint, containerViewLeftSpaceConstraint, containerViewBottomSpaceConstraint!]) - + if (isAlert()) { // ContainerView let alertViewCenterXConstraint = NSLayoutConstraint(item: alertView, attribute: .centerX, relatedBy: .equal, toItem: containerView, attribute: .centerX, multiplier: 1.0, constant: 0.0) let alertViewCenterYConstraint = NSLayoutConstraint(item: alertView, attribute: .centerY, relatedBy: .equal, toItem: containerView, attribute: .centerY, multiplier: 1.0, constant: 0.0) containerView.addConstraints([alertViewCenterXConstraint, alertViewCenterYConstraint]) - + // AlertView let alertViewWidthConstraint = NSLayoutConstraint(item: alertView, attribute: .width, relatedBy: .equal, toItem: nil, attribute: .width, multiplier: 1.0, constant: alertViewWidth) alertViewHeightConstraint = NSLayoutConstraint(item: alertView, attribute: .height, relatedBy: .equal, toItem: nil, attribute: .height, multiplier: 1.0, constant: 1000.0) alertView.addConstraints([alertViewWidthConstraint, alertViewHeightConstraint!]) - + } else { // ContainerView let alertViewCenterXConstraint = NSLayoutConstraint(item: alertView, attribute: .centerX, relatedBy: .equal, toItem: containerView, attribute: .centerX, multiplier: 1.0, constant: 0.0) let alertViewBottomSpaceConstraint = NSLayoutConstraint(item: alertView, attribute: .bottom, relatedBy: .equal, toItem: containerView, attribute: .bottom, multiplier: 1.0, constant: actionSheetBounceHeight) let alertViewWidthConstraint = NSLayoutConstraint(item: alertView, attribute: .width, relatedBy: .equal, toItem: containerView, attribute: .width, multiplier: 1.0, constant: 0.0) containerView.addConstraints([alertViewCenterXConstraint, alertViewBottomSpaceConstraint, alertViewWidthConstraint]) - + // AlertView alertViewHeightConstraint = NSLayoutConstraint(item: alertView, attribute: .height, relatedBy: .equal, toItem: nil, attribute: .height, multiplier: 1.0, constant: 1000.0) alertView.addConstraint(alertViewHeightConstraint!) } - + // AlertView let textAreaScrollViewTopSpaceConstraint = NSLayoutConstraint(item: textAreaScrollView, attribute: .top, relatedBy: .equal, toItem: alertView, attribute: .top, multiplier: 1.0, constant: 0.0) let textAreaScrollViewRightSpaceConstraint = NSLayoutConstraint(item: textAreaScrollView, attribute: .right, relatedBy: .equal, toItem: alertView, attribute: .right, multiplier: 1.0, constant: 0.0) @@ -404,7 +404,7 @@ open class DOAlertController : UIViewController, UITextFieldDelegate, UIViewCont let buttonAreaScrollViewLeftSpaceConstraint = NSLayoutConstraint(item: buttonAreaScrollView, attribute: .left, relatedBy: .equal, toItem: alertView, attribute: .left, multiplier: 1.0, constant: 0.0) let buttonAreaScrollViewBottomSpaceConstraint = NSLayoutConstraint(item: buttonAreaScrollView, attribute: .bottom, relatedBy: .equal, toItem: alertView, attribute: .bottom, multiplier: 1.0, constant: isAlert() ? 0.0 : -actionSheetBounceHeight) alertView.addConstraints([textAreaScrollViewTopSpaceConstraint, textAreaScrollViewRightSpaceConstraint, textAreaScrollViewLeftSpaceConstraint, textAreaScrollViewBottomSpaceConstraint, buttonAreaScrollViewRightSpaceConstraint, buttonAreaScrollViewLeftSpaceConstraint, buttonAreaScrollViewBottomSpaceConstraint]) - + // TextAreaScrollView let textAreaViewTopSpaceConstraint = NSLayoutConstraint(item: textAreaView, attribute: .top, relatedBy: .equal, toItem: textAreaScrollView, attribute: .top, multiplier: 1.0, constant: 0.0) let textAreaViewRightSpaceConstraint = NSLayoutConstraint(item: textAreaView, attribute: .right, relatedBy: .equal, toItem: textAreaScrollView, attribute: .right, multiplier: 1.0, constant: 0.0) @@ -412,18 +412,18 @@ open class DOAlertController : UIViewController, UITextFieldDelegate, UIViewCont let textAreaViewBottomSpaceConstraint = NSLayoutConstraint(item: textAreaView, attribute: .bottom, relatedBy: .equal, toItem: textAreaScrollView, attribute: .bottom, multiplier: 1.0, constant: 0.0) let textAreaViewWidthConstraint = NSLayoutConstraint(item: textAreaView, attribute: .width, relatedBy: .equal, toItem: textAreaScrollView, attribute: .width, multiplier: 1.0, constant: 0.0) textAreaScrollView.addConstraints([textAreaViewTopSpaceConstraint, textAreaViewRightSpaceConstraint, textAreaViewLeftSpaceConstraint, textAreaViewBottomSpaceConstraint, textAreaViewWidthConstraint]) - + // TextArea let textAreaViewHeightConstraint = NSLayoutConstraint(item: textAreaView, attribute: .height, relatedBy: .equal, toItem: textContainer, attribute: .height, multiplier: 1.0, constant: 0.0) let textContainerTopSpaceConstraint = NSLayoutConstraint(item: textContainer, attribute: .top, relatedBy: .equal, toItem: textAreaView, attribute: .top, multiplier: 1.0, constant: 0.0) let textContainerCenterXConstraint = NSLayoutConstraint(item: textContainer, attribute: .centerX, relatedBy: .equal, toItem: textAreaView, attribute: .centerX, multiplier: 1.0, constant: 0.0) textAreaView.addConstraints([textAreaViewHeightConstraint, textContainerTopSpaceConstraint, textContainerCenterXConstraint]) - + // TextContainer let textContainerWidthConstraint = NSLayoutConstraint(item: textContainer, attribute: .width, relatedBy: .equal, toItem: nil, attribute: .width, multiplier: 1.0, constant: innerContentWidth) textContainerHeightConstraint = NSLayoutConstraint(item: textContainer, attribute: .height, relatedBy: .equal, toItem: nil, attribute: .height, multiplier: 1.0, constant: 0.0) textContainer.addConstraints([textContainerWidthConstraint, textContainerHeightConstraint!]) - + // ButtonAreaScrollView buttonAreaScrollViewHeightConstraint = NSLayoutConstraint(item: buttonAreaScrollView, attribute: .height, relatedBy: .equal, toItem: nil, attribute: .height, multiplier: 1.0, constant: 0.0) let buttonAreaViewTopSpaceConstraint = NSLayoutConstraint(item: buttonAreaView, attribute: .top, relatedBy: .equal, toItem: buttonAreaScrollView, attribute: .top, multiplier: 1.0, constant: 0.0) @@ -432,34 +432,34 @@ open class DOAlertController : UIViewController, UITextFieldDelegate, UIViewCont let buttonAreaViewBottomSpaceConstraint = NSLayoutConstraint(item: buttonAreaView, attribute: .bottom, relatedBy: .equal, toItem: buttonAreaScrollView, attribute: .bottom, multiplier: 1.0, constant: 0.0) let buttonAreaViewWidthConstraint = NSLayoutConstraint(item: buttonAreaView, attribute: .width, relatedBy: .equal, toItem: buttonAreaScrollView, attribute: .width, multiplier: 1.0, constant: 0.0) buttonAreaScrollView.addConstraints([buttonAreaScrollViewHeightConstraint!, buttonAreaViewTopSpaceConstraint, buttonAreaViewRightSpaceConstraint, buttonAreaViewLeftSpaceConstraint, buttonAreaViewBottomSpaceConstraint, buttonAreaViewWidthConstraint]) - + // ButtonArea let buttonAreaViewHeightConstraint = NSLayoutConstraint(item: buttonAreaView, attribute: .height, relatedBy: .equal, toItem: buttonContainer, attribute: .height, multiplier: 1.0, constant: 0.0) let buttonContainerTopSpaceConstraint = NSLayoutConstraint(item: buttonContainer, attribute: .top, relatedBy: .equal, toItem: buttonAreaView, attribute: .top, multiplier: 1.0, constant: 0.0) let buttonContainerCenterXConstraint = NSLayoutConstraint(item: buttonContainer, attribute: .centerX, relatedBy: .equal, toItem: buttonAreaView, attribute: .centerX, multiplier: 1.0, constant: 0.0) buttonAreaView.addConstraints([buttonAreaViewHeightConstraint, buttonContainerTopSpaceConstraint, buttonContainerCenterXConstraint]) - + // ButtonContainer let buttonContainerWidthConstraint = NSLayoutConstraint(item: buttonContainer, attribute: .width, relatedBy: .equal, toItem: nil, attribute: .width, multiplier: 1.0, constant: innerContentWidth) buttonContainerHeightConstraint = NSLayoutConstraint(item: buttonContainer, attribute: .height, relatedBy: .equal, toItem: nil, attribute: .height, multiplier: 1.0, constant: 0.0) buttonContainer.addConstraints([buttonContainerWidthConstraint, buttonContainerHeightConstraint!]) - + //------------------------------ // Layout & Color Settings //------------------------------ overlayView.backgroundColor = overlayColor alertView.backgroundColor = alertViewBgColor - + //------------------------------ // TextArea Layout //------------------------------ let hasTitle: Bool = title != nil && title != "" let hasMessage: Bool = message != nil && message != "" let hasTextField: Bool = textFields != nil && textFields!.count > 0 - + var textAreaPositionY: CGFloat = alertViewPadding if (!isAlert()) {textAreaPositionY += alertViewPadding} - + // TitleLabel if (hasTitle) { titleLabel.frame.size = CGSize(width: innerContentWidth, height: 0.0) @@ -473,7 +473,7 @@ open class DOAlertController : UIViewController, UITextFieldDelegate, UIViewCont textContainer.addSubview(titleLabel) textAreaPositionY += titleLabel.frame.height + 5.0 } - + // MessageView if (hasMessage) { messageView.frame.size = CGSize(width: innerContentWidth, height: 0.0) @@ -487,46 +487,46 @@ open class DOAlertController : UIViewController, UITextFieldDelegate, UIViewCont textContainer.addSubview(messageView) textAreaPositionY += messageView.frame.height + 5.0 } - + // TextFieldContainerView if (hasTextField) { if (hasTitle || hasMessage) { textAreaPositionY += 5.0 } - + textFieldContainerView.backgroundColor = textFieldBorderColor textFieldContainerView.layer.masksToBounds = true textFieldContainerView.layer.cornerRadius = textFieldCornerRadius textFieldContainerView.layer.borderWidth = 0.5 textFieldContainerView.layer.borderColor = textFieldBorderColor.cgColor textContainer.addSubview(textFieldContainerView) - + var textFieldContainerHeight: CGFloat = 0.0 - + // TextFields for (_, obj) in (textFields!).enumerated() { let textField = obj as! UITextField textField.frame = CGRect(x: 0.0, y: textFieldContainerHeight, width: innerContentWidth, height: textField.frame.height) textFieldContainerHeight += textField.frame.height + 0.5 } - + textFieldContainerHeight -= 0.5 textFieldContainerView.frame = CGRect(x: 0.0, y: textAreaPositionY, width: innerContentWidth, height: textFieldContainerHeight) textAreaPositionY += textFieldContainerHeight + 5.0 } - + if (!hasTitle && !hasMessage && !hasTextField) { textAreaPositionY = 0.0 } - + // TextAreaScrollView textAreaHeight = textAreaPositionY textAreaScrollView.contentSize = CGSize(width: alertViewWidth, height: textAreaHeight) textContainerHeightConstraint?.constant = textAreaHeight - + //------------------------------ // ButtonArea Layout //------------------------------ var buttonAreaPositionY: CGFloat = buttonMargin - + // Buttons if (isAlert() && buttons.count == 2) { let buttonWidth = (innerContentWidth - buttonMargin) / 2 @@ -557,7 +557,7 @@ open class DOAlertController : UIViewController, UITextFieldDelegate, UIViewCont cancelButtonTag = button.tag } } - + // Cancel Button if (cancelButtonTag != 0) { if (!isAlert() && buttons.count > 1) { @@ -576,16 +576,16 @@ open class DOAlertController : UIViewController, UITextFieldDelegate, UIViewCont buttonAreaPositionY -= buttonMargin } buttonAreaPositionY += alertViewPadding - + if (buttons.count == 0) { buttonAreaPositionY = 0.0 } - + // ButtonAreaScrollView Height buttonAreaHeight = buttonAreaPositionY buttonAreaScrollView.contentSize = CGSize(width: alertViewWidth, height: buttonAreaHeight) buttonContainerHeightConstraint?.constant = buttonAreaHeight - + //------------------------------ // AlertView Layout //------------------------------ @@ -593,9 +593,10 @@ open class DOAlertController : UIViewController, UITextFieldDelegate, UIViewCont reloadAlertViewHeight() alertView.frame.size = CGSize(width: alertViewWidth, height: alertViewHeightConstraint?.constant ?? 150) } - + // Reload AlertView Height - open func reloadAlertViewHeight() { + func reloadAlertViewHeight() { + var screenSize = self.presentingViewController != nil ? self.presentingViewController!.view.bounds.size : UIScreen.main.bounds.size if ((UIDevice.current.systemVersion as NSString).floatValue < 8.0) { if (UIInterfaceOrientationIsLandscape(currentOrientation())) { @@ -603,10 +604,10 @@ open class DOAlertController : UIViewController, UITextFieldDelegate, UIViewCont } } let maxHeight = screenSize.height - keyboardHeight - + // for avoiding constraint error buttonAreaScrollViewHeightConstraint?.constant = 0.0 - + // AlertView Height Constraint var alertViewHeight = textAreaHeight + buttonAreaHeight if (alertViewHeight > maxHeight) { @@ -616,7 +617,7 @@ open class DOAlertController : UIViewController, UITextFieldDelegate, UIViewCont alertViewHeight += actionSheetBounceHeight } alertViewHeightConstraint?.constant = alertViewHeight - + // ButtonAreaScrollView Height Constraint var buttonAreaScrollViewHeight = buttonAreaHeight if (buttonAreaScrollViewHeight > maxHeight) { @@ -624,7 +625,7 @@ open class DOAlertController : UIViewController, UITextFieldDelegate, UIViewCont } buttonAreaScrollViewHeightConstraint?.constant = buttonAreaScrollViewHeight } - + // Button Tapped Action func buttonTapped(_ sender: UIButton) { sender.isSelected = true @@ -634,9 +635,9 @@ open class DOAlertController : UIViewController, UITextFieldDelegate, UIViewCont } self.dismiss(animated: true, completion: nil) } - + // Handle ContainerView tap gesture - open func handleContainerViewTapGesture(_ sender: AnyObject) { + func handleContainerViewTapGesture(_ sender: AnyObject) { // cancel action let action = actions[cancelButtonTag - 1] as! DOAlertAction if (action.handler != nil) { @@ -644,9 +645,9 @@ open class DOAlertController : UIViewController, UITextFieldDelegate, UIViewCont } self.dismiss(animated: true, completion: nil) } - + // UIColor -> UIImage - open func createImageFromUIColor(_ color: UIColor) -> UIImage { + func createImageFromUIColor(_ color: UIColor) -> UIImage { let rect = CGRect(x: 0, y: 0, width: 1, height: 1) UIGraphicsBeginImageContext(rect.size) let contextRef: CGContext = UIGraphicsGetCurrentContext()! @@ -656,16 +657,16 @@ open class DOAlertController : UIViewController, UITextFieldDelegate, UIViewCont UIGraphicsEndImageContext() return img } - + // MARK : Handle NSNotification Method - @objc open func handleAlertActionEnabledDidChangeNotification(_ notification: Notification) { + @objc func handleAlertActionEnabledDidChangeNotification(_ notification: Notification) { for i in 0.. Void)!) { - + // You can add a text field only if the preferredStyle property is set to DOAlertControllerStyle.Alert. if (!isAlert()) { let error: NSError? = nil @@ -733,25 +734,25 @@ open class DOAlertController : UIViewController, UITextFieldDelegate, UIViewCont if (textFields == nil) { textFields = [] } - + let textField = UITextField() textField.frame.size = CGSize(width: innerContentWidth, height: textFieldHeight) textField.borderStyle = UITextBorderStyle.none textField.backgroundColor = textFieldBgColor textField.delegate = self - + if ((configurationHandler) != nil) { configurationHandler(textField) } - + textFields!.append(textField) textFieldContainerView.addSubview(textField) } - + open func isAlert() -> Bool { return preferredStyle == .alert } - + // MARK: UITextFieldDelegate Methods - + open func textFieldShouldReturn(_ textField: UITextField) -> Bool { if (textField.canResignFirstResponder) { textField.resignFirstResponder() @@ -759,13 +760,14 @@ open class DOAlertController : UIViewController, UITextFieldDelegate, UIViewCont } return true } - + // MARK: UIViewControllerTransitioningDelegate Methods - open func animationController(forPresented presented: UIViewController, presenting: UIViewController, source: UIViewController) -> UIViewControllerAnimatedTransitioning? { + open + func animationController(forPresented presented: UIViewController, presenting: UIViewController, source: UIViewController) -> UIViewControllerAnimatedTransitioning? { layoutView(presenting) return DOAlertAnimation(isPresenting: true) } - + open func animationController(forDismissed dismissed: UIViewController) -> UIViewControllerAnimatedTransitioning? { return DOAlertAnimation(isPresenting: false) } From 28a23d1fcfbba859f5ade35a908e7dbc9fa48952 Mon Sep 17 00:00:00 2001 From: Nicolas Klein Date: Wed, 19 Jul 2017 11:25:09 +0200 Subject: [PATCH 09/11] fixes build --- DOAlertController.xcodeproj/project.pbxproj | 6 ++++-- Info.plist | 24 +++++++++++++++++++++ 2 files changed, 28 insertions(+), 2 deletions(-) create mode 100644 Info.plist diff --git a/DOAlertController.xcodeproj/project.pbxproj b/DOAlertController.xcodeproj/project.pbxproj index 8099d60..90e6807 100644 --- a/DOAlertController.xcodeproj/project.pbxproj +++ b/DOAlertController.xcodeproj/project.pbxproj @@ -13,6 +13,7 @@ /* Begin PBXFileReference section */ DB9950911F1F50890061E80C /* DOAlertController.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = DOAlertController.framework; sourceTree = BUILT_PRODUCTS_DIR; }; DB99509C1F1F50C40061E80C /* DOAlertController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DOAlertController.swift; sourceTree = ""; }; + DB9950B31F1F5CD70061E80C /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -31,6 +32,7 @@ children = ( DB9950931F1F50890061E80C /* DOAlertController */, DB9950921F1F50890061E80C /* Products */, + DB9950B31F1F5CD70061E80C /* Info.plist */, ); sourceTree = ""; }; @@ -246,7 +248,7 @@ DYLIB_COMPATIBILITY_VERSION = 1; DYLIB_CURRENT_VERSION = 1; DYLIB_INSTALL_NAME_BASE = "@rpath"; - INFOPLIST_FILE = DOAlertController/Info.plist; + INFOPLIST_FILE = "$(SRCROOT)/Info.plist"; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = co.devlog.DOAlertController; @@ -266,7 +268,7 @@ DYLIB_COMPATIBILITY_VERSION = 1; DYLIB_CURRENT_VERSION = 1; DYLIB_INSTALL_NAME_BASE = "@rpath"; - INFOPLIST_FILE = DOAlertController/Info.plist; + INFOPLIST_FILE = "$(SRCROOT)/Info.plist"; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = co.devlog.DOAlertController; diff --git a/Info.plist b/Info.plist new file mode 100644 index 0000000..fbe1e6b --- /dev/null +++ b/Info.plist @@ -0,0 +1,24 @@ + + + + + CFBundleDevelopmentRegion + en + CFBundleExecutable + $(EXECUTABLE_NAME) + CFBundleIdentifier + $(PRODUCT_BUNDLE_IDENTIFIER) + CFBundleInfoDictionaryVersion + 6.0 + CFBundleName + $(PRODUCT_NAME) + CFBundlePackageType + FMWK + CFBundleShortVersionString + 1.0 + CFBundleVersion + $(CURRENT_PROJECT_VERSION) + NSPrincipalClass + + + From 2d530b6cb44047f68bf71f37d32b4910fffb9011 Mon Sep 17 00:00:00 2001 From: Nicolas Klein Date: Wed, 19 Jul 2017 11:36:11 +0200 Subject: [PATCH 10/11] fixes minimum target deployment --- DOAlertController.xcodeproj/project.pbxproj | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/DOAlertController.xcodeproj/project.pbxproj b/DOAlertController.xcodeproj/project.pbxproj index 90e6807..ef95c5d 100644 --- a/DOAlertController.xcodeproj/project.pbxproj +++ b/DOAlertController.xcodeproj/project.pbxproj @@ -180,7 +180,7 @@ GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; - IPHONEOS_DEPLOYMENT_TARGET = 10.3; + IPHONEOS_DEPLOYMENT_TARGET = 9.0; MTL_ENABLE_DEBUG_INFO = YES; ONLY_ACTIVE_ARCH = YES; SDKROOT = iphoneos; @@ -228,7 +228,7 @@ GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; - IPHONEOS_DEPLOYMENT_TARGET = 10.3; + IPHONEOS_DEPLOYMENT_TARGET = 9.0; MTL_ENABLE_DEBUG_INFO = NO; SDKROOT = iphoneos; SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; From 9ad3b84e5f94a2788cf7d6c23c27747bba4772e3 Mon Sep 17 00:00:00 2001 From: Nicolas Klein Date: Wed, 22 Jul 2020 17:50:45 +0200 Subject: [PATCH 11/11] Update to Swift 4.2 --- DOAlertController/DOAlertController.swift | 38 +++++++++++------------ 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/DOAlertController/DOAlertController.swift b/DOAlertController/DOAlertController.swift index 37234a7..265c970 100644 --- a/DOAlertController/DOAlertController.swift +++ b/DOAlertController/DOAlertController.swift @@ -255,8 +255,8 @@ open class DOAlertController : UIViewController, UITextFieldDelegate, UIViewCont // NotificationCenter NotificationCenter.default.addObserver(self, selector: #selector(DOAlertController.handleAlertActionEnabledDidChangeNotification(_:)), name: NSNotification.Name(rawValue: DOAlertActionEnabledDidChangeNotification), object: nil) - NotificationCenter.default.addObserver(self, selector: #selector(DOAlertController.handleKeyboardWillShowNotification(_:)), name: NSNotification.Name.UIKeyboardWillShow, object: nil) - NotificationCenter.default.addObserver(self, selector: #selector(DOAlertController.handleKeyboardWillHideNotification(_:)), name: NSNotification.Name.UIKeyboardWillHide, object: nil) + NotificationCenter.default.addObserver(self, selector: #selector(DOAlertController.handleKeyboardWillShowNotification(_:)), name: UIResponder.keyboardWillShowNotification, object: nil) + NotificationCenter.default.addObserver(self, selector: #selector(DOAlertController.handleKeyboardWillHideNotification(_:)), name: UIResponder.keyboardWillHideNotification, object: nil) // Delegate self.transitioningDelegate = self @@ -304,7 +304,7 @@ open class DOAlertController : UIViewController, UITextFieldDelegate, UIViewCont // Screen Size var screenSize = presenting != nil ? presenting!.view.bounds.size : UIScreen.main.bounds.size if ((UIDevice.current.systemVersion as NSString).floatValue < 8.0) { - if (UIInterfaceOrientationIsLandscape(currentOrientation())) { + if (currentOrientation().isLandscape) { screenSize = CGSize(width: screenSize.height, height: screenSize.width) } } @@ -534,8 +534,8 @@ open class DOAlertController : UIViewController, UITextFieldDelegate, UIViewCont for button in buttons { let action = actions[button.tag - 1] as! DOAlertAction button.titleLabel?.font = buttonFont[action.style] - button.setTitleColor(buttonTextColor[action.style], for: UIControlState()) - button.setBackgroundImage(createImageFromUIColor(buttonBgColor[action.style]!), for: UIControlState()) + button.setTitleColor(buttonTextColor[action.style], for: .normal) + button.setBackgroundImage(createImageFromUIColor(buttonBgColor[action.style]!), for: .normal) button.setBackgroundImage(createImageFromUIColor(buttonBgColorHighlighted[action.style]!), for: .highlighted) button.setBackgroundImage(createImageFromUIColor(buttonBgColorHighlighted[action.style]!), for: .selected) button.frame = CGRect(x: buttonPositionX, y: buttonAreaPositionY, width: buttonWidth, height: buttonHeight) @@ -547,8 +547,8 @@ open class DOAlertController : UIViewController, UITextFieldDelegate, UIViewCont let action = actions[button.tag - 1] as! DOAlertAction if (action.style != DOAlertActionStyle.cancel) { button.titleLabel?.font = buttonFont[action.style] - button.setTitleColor(buttonTextColor[action.style], for: UIControlState()) - button.setBackgroundImage(createImageFromUIColor(buttonBgColor[action.style]!), for: UIControlState()) + button.setTitleColor(buttonTextColor[action.style], for: .normal) + button.setBackgroundImage(createImageFromUIColor(buttonBgColor[action.style]!), for: .normal) button.setBackgroundImage(createImageFromUIColor(buttonBgColorHighlighted[action.style]!), for: .highlighted) button.setBackgroundImage(createImageFromUIColor(buttonBgColorHighlighted[action.style]!), for: .selected) button.frame = CGRect(x: 0, y: buttonAreaPositionY, width: innerContentWidth, height: buttonHeight) @@ -566,8 +566,8 @@ open class DOAlertController : UIViewController, UITextFieldDelegate, UIViewCont let button = buttonAreaScrollView.viewWithTag(cancelButtonTag) as! UIButton let action = actions[cancelButtonTag - 1] as! DOAlertAction button.titleLabel?.font = buttonFont[action.style] - button.setTitleColor(buttonTextColor[action.style], for: UIControlState()) - button.setBackgroundImage(createImageFromUIColor(buttonBgColor[action.style]!), for: UIControlState()) + button.setTitleColor(buttonTextColor[action.style], for: .normal) + button.setBackgroundImage(createImageFromUIColor(buttonBgColor[action.style]!), for: .normal) button.setBackgroundImage(createImageFromUIColor(buttonBgColorHighlighted[action.style]!), for: .highlighted) button.setBackgroundImage(createImageFromUIColor(buttonBgColorHighlighted[action.style]!), for: .selected) button.frame = CGRect(x: 0, y: buttonAreaPositionY, width: innerContentWidth, height: buttonHeight) @@ -599,7 +599,7 @@ open class DOAlertController : UIViewController, UITextFieldDelegate, UIViewCont var screenSize = self.presentingViewController != nil ? self.presentingViewController!.view.bounds.size : UIScreen.main.bounds.size if ((UIDevice.current.systemVersion as NSString).floatValue < 8.0) { - if (UIInterfaceOrientationIsLandscape(currentOrientation())) { + if (currentOrientation().isLandscape) { screenSize = CGSize(width: screenSize.height, height: screenSize.width) } } @@ -627,7 +627,7 @@ open class DOAlertController : UIViewController, UITextFieldDelegate, UIViewCont } // Button Tapped Action - func buttonTapped(_ sender: UIButton) { + @objc func buttonTapped(_ sender: UIButton) { sender.isSelected = true let action = actions[sender.tag - 1] as! DOAlertAction if (action.handler != nil) { @@ -637,7 +637,7 @@ open class DOAlertController : UIViewController, UITextFieldDelegate, UIViewCont } // Handle ContainerView tap gesture - func handleContainerViewTapGesture(_ sender: AnyObject) { + @objc func handleContainerViewTapGesture(_ sender: AnyObject) { // cancel action let action = actions[cancelButtonTag - 1] as! DOAlertAction if (action.handler != nil) { @@ -662,16 +662,16 @@ open class DOAlertController : UIViewController, UITextFieldDelegate, UIViewCont @objc func handleAlertActionEnabledDidChangeNotification(_ notification: Notification) { for i in 0..