diff --git a/DOAlertController-DEMO/DOAlertController-DEMO.xcodeproj/project.pbxproj b/DOAlertController-DEMO/DOAlertController-DEMO.xcodeproj/project.pbxproj old mode 100644 new mode 100755 index 3c7c9cc..3fdaced --- a/DOAlertController-DEMO/DOAlertController-DEMO.xcodeproj/project.pbxproj +++ b/DOAlertController-DEMO/DOAlertController-DEMO.xcodeproj/project.pbxproj @@ -167,14 +167,16 @@ 4F47CAA31AE26BD100BF71E4 /* Project object */ = { isa = PBXProject; attributes = { - LastUpgradeCheck = 0620; + LastUpgradeCheck = 0810; ORGANIZATIONNAME = "Daiki Okumura"; TargetAttributes = { 4F47CAAA1AE26BD100BF71E4 = { CreatedOnToolsVersion = 6.2; + LastSwiftMigration = 0810; }; 4F47CABF1AE26BD100BF71E4 = { CreatedOnToolsVersion = 6.2; + LastSwiftMigration = 0810; TestTargetID = 4F47CAAA1AE26BD100BF71E4; }; }; @@ -280,15 +282,19 @@ CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 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; 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", @@ -322,8 +328,10 @@ CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 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"; @@ -331,6 +339,7 @@ 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; @@ -340,6 +349,7 @@ IPHONEOS_DEPLOYMENT_TARGET = 8.2; MTL_ENABLE_DEBUG_INFO = NO; SDKROOT = iphoneos; + SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; VALIDATE_PRODUCT = YES; }; name = Release; @@ -349,9 +359,11 @@ buildSettings = { ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; INFOPLIST_FILE = "DOAlertController-DEMO/Info.plist"; - IPHONEOS_DEPLOYMENT_TARGET = 7.0; + IPHONEOS_DEPLOYMENT_TARGET = 8.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; + PRODUCT_BUNDLE_IDENTIFIER = "co.devlog.$(PRODUCT_NAME:rfc1034identifier)"; PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_VERSION = 3.0; TARGETED_DEVICE_FAMILY = "1,2"; }; name = Debug; @@ -361,9 +373,11 @@ buildSettings = { ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; INFOPLIST_FILE = "DOAlertController-DEMO/Info.plist"; - IPHONEOS_DEPLOYMENT_TARGET = 7.0; + IPHONEOS_DEPLOYMENT_TARGET = 8.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; + PRODUCT_BUNDLE_IDENTIFIER = "co.devlog.$(PRODUCT_NAME:rfc1034identifier)"; PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_VERSION = 3.0; TARGETED_DEVICE_FAMILY = "1,2"; }; name = Release; @@ -382,7 +396,9 @@ ); INFOPLIST_FILE = "DOAlertController-DEMOTests/Info.plist"; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; + PRODUCT_BUNDLE_IDENTIFIER = "co.devlog.$(PRODUCT_NAME:rfc1034identifier)"; PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_VERSION = 3.0; TEST_HOST = "$(BUILT_PRODUCTS_DIR)/DOAlertController-DEMO.app/DOAlertController-DEMO"; }; name = Debug; @@ -397,7 +413,9 @@ ); INFOPLIST_FILE = "DOAlertController-DEMOTests/Info.plist"; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; + PRODUCT_BUNDLE_IDENTIFIER = "co.devlog.$(PRODUCT_NAME:rfc1034identifier)"; PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_VERSION = 3.0; TEST_HOST = "$(BUILT_PRODUCTS_DIR)/DOAlertController-DEMO.app/DOAlertController-DEMO"; }; name = Release; diff --git a/DOAlertController-DEMO/DOAlertController-DEMO.xcodeproj/project.xcworkspace/contents.xcworkspacedata b/DOAlertController-DEMO/DOAlertController-DEMO.xcodeproj/project.xcworkspace/contents.xcworkspacedata old mode 100644 new mode 100755 diff --git a/DOAlertController-DEMO/DOAlertController-DEMO.xcodeproj/project.xcworkspace/xcuserdata/dip.xcuserdatad/UserInterfaceState.xcuserstate b/DOAlertController-DEMO/DOAlertController-DEMO.xcodeproj/project.xcworkspace/xcuserdata/dip.xcuserdatad/UserInterfaceState.xcuserstate new file mode 100644 index 0000000..ccf8183 Binary files /dev/null and b/DOAlertController-DEMO/DOAlertController-DEMO.xcodeproj/project.xcworkspace/xcuserdata/dip.xcuserdatad/UserInterfaceState.xcuserstate differ diff --git a/DOAlertController-DEMO/DOAlertController-DEMO.xcodeproj/project.xcworkspace/xcuserdata/okumuradaiki.xcuserdatad/UserInterfaceState.xcuserstate b/DOAlertController-DEMO/DOAlertController-DEMO.xcodeproj/project.xcworkspace/xcuserdata/okumuradaiki.xcuserdatad/UserInterfaceState.xcuserstate old mode 100644 new mode 100755 diff --git a/DOAlertController-DEMO/DOAlertController-DEMO.xcodeproj/xcuserdata/dip.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist b/DOAlertController-DEMO/DOAlertController-DEMO.xcodeproj/xcuserdata/dip.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist new file mode 100644 index 0000000..fe2b454 --- /dev/null +++ b/DOAlertController-DEMO/DOAlertController-DEMO.xcodeproj/xcuserdata/dip.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist @@ -0,0 +1,5 @@ + + + diff --git a/DOAlertController-DEMO/DOAlertController-DEMO.xcodeproj/xcuserdata/dip.xcuserdatad/xcschemes/DOAlertController-DEMO.xcscheme b/DOAlertController-DEMO/DOAlertController-DEMO.xcodeproj/xcuserdata/dip.xcuserdatad/xcschemes/DOAlertController-DEMO.xcscheme new file mode 100644 index 0000000..f73fe8e --- /dev/null +++ b/DOAlertController-DEMO/DOAlertController-DEMO.xcodeproj/xcuserdata/dip.xcuserdatad/xcschemes/DOAlertController-DEMO.xcscheme @@ -0,0 +1,101 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/DOAlertController-DEMO/DOAlertController-DEMO.xcodeproj/xcuserdata/dip.xcuserdatad/xcschemes/xcschememanagement.plist b/DOAlertController-DEMO/DOAlertController-DEMO.xcodeproj/xcuserdata/dip.xcuserdatad/xcschemes/xcschememanagement.plist new file mode 100644 index 0000000..2803c16 --- /dev/null +++ b/DOAlertController-DEMO/DOAlertController-DEMO.xcodeproj/xcuserdata/dip.xcuserdatad/xcschemes/xcschememanagement.plist @@ -0,0 +1,27 @@ + + + + + SchemeUserState + + DOAlertController-DEMO.xcscheme + + orderHint + 0 + + + SuppressBuildableAutocreation + + 4F47CAAA1AE26BD100BF71E4 + + primary + + + 4F47CABF1AE26BD100BF71E4 + + primary + + + + + diff --git a/DOAlertController-DEMO/DOAlertController-DEMO.xcodeproj/xcuserdata/okumuradaiki.xcuserdatad/xcschemes/DOAlertController-DEMO.xcscheme b/DOAlertController-DEMO/DOAlertController-DEMO.xcodeproj/xcuserdata/okumuradaiki.xcuserdatad/xcschemes/DOAlertController-DEMO.xcscheme old mode 100644 new mode 100755 diff --git a/DOAlertController-DEMO/DOAlertController-DEMO.xcodeproj/xcuserdata/okumuradaiki.xcuserdatad/xcschemes/xcschememanagement.plist b/DOAlertController-DEMO/DOAlertController-DEMO.xcodeproj/xcuserdata/okumuradaiki.xcuserdatad/xcschemes/xcschememanagement.plist old mode 100644 new mode 100755 diff --git a/DOAlertController-DEMO/DOAlertController-DEMO/AppDelegate.swift b/DOAlertController-DEMO/DOAlertController-DEMO/AppDelegate.swift old mode 100644 new mode 100755 index 836de47..438052c --- a/DOAlertController-DEMO/DOAlertController-DEMO/AppDelegate.swift +++ b/DOAlertController-DEMO/DOAlertController-DEMO/AppDelegate.swift @@ -14,30 +14,30 @@ class AppDelegate: UIResponder, UIApplicationDelegate { var window: UIWindow? - func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool { + func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool { // Override point for customization after application launch. return true } - func applicationWillResignActive(application: UIApplication) { + func applicationWillResignActive(_ application: UIApplication) { // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state. // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game. } - func applicationDidEnterBackground(application: UIApplication) { + func applicationDidEnterBackground(_ application: UIApplication) { // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. } - func applicationWillEnterForeground(application: UIApplication) { + func applicationWillEnterForeground(_ application: UIApplication) { // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background. } - func applicationDidBecomeActive(application: UIApplication) { + func applicationDidBecomeActive(_ application: UIApplication) { // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface. } - func applicationWillTerminate(application: UIApplication) { + func applicationWillTerminate(_ application: UIApplication) { // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. } diff --git a/DOAlertController-DEMO/DOAlertController-DEMO/Base.lproj/LaunchScreen.xib b/DOAlertController-DEMO/DOAlertController-DEMO/Base.lproj/LaunchScreen.xib old mode 100644 new mode 100755 diff --git a/DOAlertController-DEMO/DOAlertController-DEMO/Base.lproj/Main.storyboard b/DOAlertController-DEMO/DOAlertController-DEMO/Base.lproj/Main.storyboard old mode 100644 new mode 100755 diff --git a/DOAlertController-DEMO/DOAlertController-DEMO/DOAlertController.swift b/DOAlertController-DEMO/DOAlertController-DEMO/DOAlertController.swift old mode 100644 new mode 100755 index b322ec8..db45449 --- a/DOAlertController-DEMO/DOAlertController-DEMO/DOAlertController.swift +++ b/DOAlertController-DEMO/DOAlertController-DEMO/DOAlertController.swift @@ -15,14 +15,14 @@ import UIKit let DOAlertActionEnabledDidChangeNotification = "DOAlertActionEnabledDidChangeNotification" enum DOAlertActionStyle : Int { - case Default - case Cancel - case Destructive + case `default` + case cancel + case destructive } enum DOAlertControllerStyle : Int { - case ActionSheet - case Alert + case actionSheet + case alert } // MARK: DOAlertAction Class @@ -30,24 +30,24 @@ enum DOAlertControllerStyle : Int { class DOAlertAction : NSObject, NSCopying { var title: String var style: DOAlertActionStyle - var handler: ((DOAlertAction!) -> Void)! + var handler: ((DOAlertAction?) -> Void)! var enabled: Bool { didSet { if (oldValue != enabled) { - NSNotificationCenter.defaultCenter().postNotificationName(DOAlertActionEnabledDidChangeNotification, object: nil) + NotificationCenter.default.post(name: Notification.Name(rawValue: DOAlertActionEnabledDidChangeNotification), object: nil) } } } - required init(title: String, style: DOAlertActionStyle, handler: ((DOAlertAction!) -> Void)!) { + 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) + func copy(with zone: NSZone?) -> Any { + let copy = type(of: self).init(title: title, style: style, handler: handler) copy.enabled = self.enabled return copy } @@ -63,7 +63,7 @@ class DOAlertAnimation : NSObject, UIViewControllerAnimatedTransitioning { self.isPresenting = isPresenting } - func transitionDuration(transitionContext: UIViewControllerContextTransitioning) -> NSTimeInterval { + func transitionDuration(using transitionContext: UIViewControllerContextTransitioning?) -> TimeInterval { if (isPresenting) { return 0.45 } else { @@ -71,7 +71,7 @@ class DOAlertAnimation : NSObject, UIViewControllerAnimatedTransitioning { } } - func animateTransition(transitionContext: UIViewControllerContextTransitioning) { + func animateTransition(using transitionContext: UIViewControllerContextTransitioning) { if (isPresenting) { self.presentAnimateTransition(transitionContext) } else { @@ -79,36 +79,36 @@ class DOAlertAnimation : NSObject, UIViewControllerAnimatedTransitioning { } } - func presentAnimateTransition(transitionContext: UIViewControllerContextTransitioning) { + func presentAnimateTransition(_ transitionContext: UIViewControllerContextTransitioning) { - var alertController = transitionContext.viewControllerForKey(UITransitionContextToViewControllerKey) as! DOAlertController - var 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) - 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 @@ class DOAlertAnimation : NSObject, UIViewControllerAnimatedTransitioning { }) } - func dismissAnimateTransition(transitionContext: UIViewControllerContextTransitioning) { + func dismissAnimateTransition(_ transitionContext: UIViewControllerContextTransitioning) { - var 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 @@ -146,100 +146,100 @@ class DOAlertController : UIViewController, UITextFieldDelegate, UIViewControlle var message: String? // AlertController Style - private(set) var preferredStyle: DOAlertControllerStyle? + fileprivate(set) var preferredStyle: DOAlertControllerStyle? // OverlayView - private var overlayView = UIView() + fileprivate var overlayView = UIView() var overlayColor = UIColor(red:0, green:0, blue:0, alpha:0.5) // ContainerView - private var containerView = UIView() - private var containerViewBottomSpaceConstraint: NSLayoutConstraint! + fileprivate var containerView = UIView() + fileprivate var containerViewBottomSpaceConstraint: NSLayoutConstraint! // AlertView - private var alertView = UIView() + fileprivate var alertView = UIView() 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 + 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() + fileprivate 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) // MessageView - private var messageView = UILabel() + fileprivate 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) // TextFieldContainerView - private var textFieldContainerView = UIView() + fileprivate var textFieldContainerView = UIView() 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() - private let textFieldCornerRadius: CGFloat = 4.0 + fileprivate(set) var textFields: [AnyObject]? + fileprivate let textFieldHeight: CGFloat = 30.0 + 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]() - 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]() + 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] = [ - .Default : UIColor.whiteColor(), - .Cancel : UIColor.whiteColor(), - .Destructive : UIColor.whiteColor() + .default : UIColor.white, + .cancel : UIColor.white, + .destructive : UIColor.white ] 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) + .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] = [ - .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) + .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 convenience init(title: String?, message: String?, preferredStyle: DOAlertControllerStyle) { @@ -251,21 +251,21 @@ class DOAlertController : UIViewController, UITextFieldDelegate, UIViewControlle 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) } } @@ -311,101 +311,101 @@ 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) - 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]) } - override init(nibName nibNameOrNil: String?, bundle nibBundleOrNil: NSBundle?) { + override init(nibName nibNameOrNil: String?, bundle nibBundleOrNil: Bundle?) { super.init(nibName:nibNameOrNil, bundle:nibBundleOrNil) } @@ -413,16 +413,16 @@ class DOAlertController : UIViewController, UITextFieldDelegate, UIViewControlle fatalError("init(coder:) has not been implemented") } - override func viewWillAppear(animated: Bool) { + override func viewWillAppear(_ animated: Bool) { super.viewWillAppear(animated) layoutView() } - override func viewDidAppear(animated: Bool) { + 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: #selector(DOAlertController.handleContainerViewTapGesture(_:))) containerView.addGestureRecognizer(tapGesture) } } @@ -449,28 +449,28 @@ class DOAlertController : UIViewController, UITextFieldDelegate, UIViewControlle // 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,22 @@ class DOAlertController : UIViewController, UITextFieldDelegate, UIViewControlle 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 enumerate(textFields!) { + + for obj in textFields! { + 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 +508,7 @@ class DOAlertController : UIViewController, UITextFieldDelegate, UIViewControlle // TextAreaScrollView textAreaHeight = textAreaPositionY - textAreaScrollView.contentSize = CGSizeMake(alertViewWidth, textAreaHeight) + textAreaScrollView.contentSize = CGSize(width: alertViewWidth, height: textAreaHeight) textContainerHeightConstraint.constant = textAreaHeight //------------------------------ @@ -520,25 +522,25 @@ class DOAlertController : UIViewController, UITextFieldDelegate, UIViewControlle 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 @@ -550,14 +552,14 @@ 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) - 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 +572,7 @@ class DOAlertController : UIViewController, UITextFieldDelegate, UIViewControlle // ButtonAreaScrollView Height buttonAreaHeight = buttonAreaPositionY - buttonAreaScrollView.contentSize = CGSizeMake(alertViewWidth, buttonAreaHeight) + buttonAreaScrollView.contentSize = CGSize(width: alertViewWidth, height: buttonAreaHeight) buttonContainerHeightConstraint.constant = buttonAreaHeight //------------------------------ @@ -578,16 +580,16 @@ class DOAlertController : UIViewController, UITextFieldDelegate, UIViewControlle //------------------------------ // AlertView Height reloadAlertViewHeight() - alertView.frame.size = CGSizeMake(alertViewWidth, alertViewHeightConstraint.constant) + alertView.frame.size = CGSize(width: alertViewWidth, height: alertViewHeightConstraint.constant) } // Reload AlertView Height 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 +616,68 @@ class DOAlertController : UIViewController, UITextFieldDelegate, UIViewControlle } // Button Tapped Action - func buttonTapped(sender: UIButton) { - sender.selected = true + 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 - func handleContainerViewTapGesture(sender: AnyObject) { + func handleContainerViewTapGesture(_ sender: AnyObject) { // cancel action let action = actions[cancelButtonTag] as! DOAlertAction if (action.handler != nil) { action.handler(action) } - self.dismissViewControllerAnimated(true, completion: nil) + self.dismiss(animated: true, completion: nil) } // UIColor -> UIImage - func createImageFromUIColor(var color: UIColor) -> UIImage { - let rect = CGRectMake(0, 0, 1, 1) + func createImageFromUIColor(_ color: UIColor) -> UIImage { + let color = color + 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 func handleAlertActionEnabledDidChangeNotification(notification: NSNotification) { + @objc func handleAlertActionEnabledDidChangeNotification(_ notification: Notification) { for i in 0.. Void)!) { + 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"])) + + let errorDict = [ NSLocalizedDescriptionKey:"some thing dip"] + let error: NSError = NSError(domain:"DipError",code:001,userInfo: errorDict) + + NSException.raise(NSExceptionName(rawValue: "NSInternalInconsistencyException"), format: "Text fields can only be added to an alert controller of style DOAlertControllerStyleAlert", arguments:getVaList([error])) return } if (textFields == nil) { textFields = [] } - var textField = UITextField() - textField.frame.size = CGSizeMake(innerContentWidth, textFieldHeight) - textField.borderStyle = UITextBorderStyle.None + let textField = UITextField() + textField.frame.size = CGSize(width: innerContentWidth, height: textFieldHeight) + textField.borderStyle = UITextBorderStyle.none textField.backgroundColor = textFieldBgColor textField.delegate = self @@ -735,26 +742,26 @@ class DOAlertController : UIViewController, UITextFieldDelegate, UIViewControlle textFieldContainerView.addSubview(textField) } - func isAlert() -> Bool { return preferredStyle == .Alert } + func isAlert() -> Bool { return preferredStyle == .alert } // MARK: UITextFieldDelegate Methods - func textFieldShouldReturn(textField: UITextField) -> Bool { - if (textField.canResignFirstResponder()) { + 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 - func animationControllerForPresentedController(presented: UIViewController, presentingController presenting: UIViewController, sourceController source: UIViewController) -> UIViewControllerAnimatedTransitioning? { + func animationController(forPresented presented: UIViewController, presenting: UIViewController, source: UIViewController) -> UIViewControllerAnimatedTransitioning? { layoutView() return DOAlertAnimation(isPresenting: true) } - func animationControllerForDismissedController(dismissed: UIViewController) -> UIViewControllerAnimatedTransitioning? { + func animationController(forDismissed dismissed: UIViewController) -> UIViewControllerAnimatedTransitioning? { return DOAlertAnimation(isPresenting: false) } } diff --git a/DOAlertController-DEMO/DOAlertController-DEMO/Images.xcassets/AppIcon.appiconset/Contents.json b/DOAlertController-DEMO/DOAlertController-DEMO/Images.xcassets/AppIcon.appiconset/Contents.json old mode 100644 new mode 100755 diff --git a/DOAlertController-DEMO/DOAlertController-DEMO/Info.plist b/DOAlertController-DEMO/DOAlertController-DEMO/Info.plist old mode 100644 new mode 100755 index 9b507c0..6905cc6 --- a/DOAlertController-DEMO/DOAlertController-DEMO/Info.plist +++ b/DOAlertController-DEMO/DOAlertController-DEMO/Info.plist @@ -7,7 +7,7 @@ CFBundleExecutable $(EXECUTABLE_NAME) CFBundleIdentifier - co.devlog.$(PRODUCT_NAME:rfc1034identifier) + $(PRODUCT_BUNDLE_IDENTIFIER) CFBundleInfoDictionaryVersion 6.0 CFBundleName diff --git a/DOAlertController-DEMO/DOAlertController-DEMO/ViewController.swift b/DOAlertController-DEMO/DOAlertController-DEMO/ViewController.swift old mode 100644 new mode 100755 index 3ad1408..dcf47ca --- a/DOAlertController-DEMO/DOAlertController-DEMO/ViewController.swift +++ b/DOAlertController-DEMO/DOAlertController-DEMO/ViewController.swift @@ -19,7 +19,7 @@ class ViewController : UITableViewController, UITextFieldDelegate { // A matrix of closures that should be invoked based on which table view cell is // tapped (index by section, row). - var actionMap: [[(selectedIndexPath: NSIndexPath) -> Void]] { + var actionMap: [[(_ selectedIndexPath: IndexPath) -> Void]] { return [ // Alert style alerts. [ @@ -42,39 +42,39 @@ class ViewController : UITableViewController, UITextFieldDelegate { // MARK: DOAlertControllerStyleAlert Style Alerts /// Show an alert with an "Okay" button. - func showSimpleAlert(_: NSIndexPath) { + func showSimpleAlert(_: IndexPath) { let title = "Simple Alert" let message = "A message should be a short, complete sentence." let cancelButtonTitle = "OK" - let alertController = DOAlertController(title: title, message: message, preferredStyle: .Alert) + let alertController = DOAlertController(title: title, message: message, preferredStyle: .alert) // Create the action. - let cancelAction = DOAlertAction(title: cancelButtonTitle, style: .Cancel) { action in + let cancelAction = DOAlertAction(title: cancelButtonTitle, style: .cancel) { action in NSLog("The simple alert's cancel action occured.") } // Add the action. alertController.addAction(cancelAction) - presentViewController(alertController, animated: true, completion: nil) + present(alertController, animated: true, completion: nil) } /// Show an alert with an "Okay" and "Cancel" button. - func showOkayCancelAlert(_: NSIndexPath) { + func showOkayCancelAlert(_: IndexPath) { let title = "Okay/Cancel Alert" let message = "A message should be a short, complete sentence." let cancelButtonTitle = "Cancel" let otherButtonTitle = "OK" - let alertCotroller = DOAlertController(title: title, message: message, preferredStyle: .Alert) + let alertCotroller = DOAlertController(title: title, message: message, preferredStyle: .alert) // Create the actions. - let cancelAction = DOAlertAction(title: cancelButtonTitle, style: .Cancel) { action in + let cancelAction = DOAlertAction(title: cancelButtonTitle, style: .cancel) { action in NSLog("The \"Okay/Cancel\" alert's cancel action occured.") } - let otherAction = DOAlertAction(title: otherButtonTitle, style: .Default) { action in + let otherAction = DOAlertAction(title: otherButtonTitle, style: .default) { action in NSLog("The \"Okay/Cancel\" alert's other action occured.") } @@ -82,11 +82,11 @@ class ViewController : UITableViewController, UITextFieldDelegate { alertCotroller.addAction(cancelAction) alertCotroller.addAction(otherAction) - presentViewController(alertCotroller, animated: true, completion: nil) + present(alertCotroller, animated: true, completion: nil) } /// Show an alert with two custom buttons. - func showOtherAlert(_: NSIndexPath) { + func showOtherAlert(_: IndexPath) { let title = "Other Alert" let message = "A message should be a short, complete sentence." let cancelButtonTitle = "Cancel" @@ -94,22 +94,22 @@ class ViewController : UITableViewController, UITextFieldDelegate { let otherButtonTitleTwo = "Choice Two" let destructiveButtonTitle = "Destructive" - let alertController = DOAlertController(title: title, message: message, preferredStyle: .Alert) + let alertController = DOAlertController(title: title, message: message, preferredStyle: .alert) // Create the actions. - let cancelAction = DOAlertAction(title: cancelButtonTitle, style: .Cancel) { action in + let cancelAction = DOAlertAction(title: cancelButtonTitle, style: .cancel) { action in NSLog("The \"Other\" alert's cancel action occured.") } - let otherButtonOneAction = DOAlertAction(title: otherButtonTitleOne, style: .Default) { action in + let otherButtonOneAction = DOAlertAction(title: otherButtonTitleOne, style: .default) { action in NSLog("The \"Other\" alert's other button one action occured.") } - let otherButtonTwoAction = DOAlertAction(title: otherButtonTitleTwo, style: .Default) { action in + let otherButtonTwoAction = DOAlertAction(title: otherButtonTitleTwo, style: .default) { action in NSLog("The \"Other\" alert's other button two action occured.") } - let destructiveButtonAction = DOAlertAction(title: destructiveButtonTitle, style: .Destructive) { action in + let destructiveButtonAction = DOAlertAction(title: destructiveButtonTitle, style: .destructive) { action in NSLog("The \"Other\" alert's destructive button action occured.") } @@ -119,17 +119,17 @@ class ViewController : UITableViewController, UITextFieldDelegate { alertController.addAction(otherButtonTwoAction) alertController.addAction(destructiveButtonAction) - presentViewController(alertController, animated: true, completion: nil) + present(alertController, animated: true, completion: nil) } /// Show a text entry alert with two custom buttons. - func showTextEntryAlert(_: NSIndexPath) { + func showTextEntryAlert(_: IndexPath) { let title = "Text Entry Alert" let message = "A message should be a short, complete sentence." let cancelButtonTitle = "Cancel" let otherButtonTitle = "OK" - let alertController = DOAlertController(title: title, message: message, preferredStyle: .Alert) + let alertController = DOAlertController(title: title, message: message, preferredStyle: .alert) // Add the text field for text entry. alertController.addTextFieldWithConfigurationHandler { textField in @@ -137,11 +137,11 @@ class ViewController : UITableViewController, UITextFieldDelegate { } // Create the actions. - let cancelAction = DOAlertAction(title: cancelButtonTitle, style: .Cancel) { action in + let cancelAction = DOAlertAction(title: cancelButtonTitle, style: .cancel) { action in NSLog("The \"Text Entry\" alert's cancel action occured.") } - let otherAction = DOAlertAction(title: otherButtonTitle, style: .Default) { action in + let otherAction = DOAlertAction(title: otherButtonTitle, style: .default) { action in NSLog("The \"Text Entry\" alert's other action occured.") } @@ -149,41 +149,41 @@ class ViewController : UITableViewController, UITextFieldDelegate { alertController.addAction(cancelAction) alertController.addAction(otherAction) - presentViewController(alertController, animated: true, completion: nil) + present(alertController, animated: true, completion: nil) } /// Show a secure text entry alert with two custom buttons. - func showSecureTextEntryAlert(_: NSIndexPath) { + func showSecureTextEntryAlert(_: IndexPath) { let title = "Secure Text Entry Alert" let message = "A message should be a short, complete sentence." let cancelButtonTitle = "Cancel" let otherButtonTitle = "OK" - let alertController = DOAlertController(title: title, message: message, preferredStyle: .Alert) + let alertController = DOAlertController(title: title, message: message, preferredStyle: .alert) // Add the text field for the secure text entry. alertController.addTextFieldWithConfigurationHandler { textField in // Listen for changes to the text field's text so that we can toggle the current // action's enabled property based on whether the user has entered a sufficiently // secure entry. - NSNotificationCenter.defaultCenter().addObserver(self, selector: "handleTextFieldTextDidChangeNotification:", name: UITextFieldTextDidChangeNotification, object: textField) + NotificationCenter.default.addObserver(self, selector: #selector(ViewController.handleTextFieldTextDidChangeNotification(_:)), name: NSNotification.Name.UITextFieldTextDidChange, object: textField) - textField.secureTextEntry = true + textField?.isSecureTextEntry = true } // Stop listening for text change notifications on the text field. This closure will be called in the two action handlers. - let removeTextFieldObserver: Void -> Void = { - NSNotificationCenter.defaultCenter().removeObserver(self, name: UITextFieldTextDidChangeNotification, object: alertController.textFields!.first) + let removeTextFieldObserver: (Void) -> Void = { + NotificationCenter.default.removeObserver(self, name: NSNotification.Name.UITextFieldTextDidChange, object: alertController.textFields!.first) } // Create the actions. - let cancelAction = DOAlertAction(title: cancelButtonTitle, style: .Cancel) { action in + let cancelAction = DOAlertAction(title: cancelButtonTitle, style: .cancel) { action in NSLog("The \"Secure Text Entry\" alert's cancel action occured.") removeTextFieldObserver() } - let otherAction = DOAlertAction(title: otherButtonTitle, style: .Default) { action in + let otherAction = DOAlertAction(title: otherButtonTitle, style: .default) { action in NSLog("The \"Secure Text Entry\" alert's other action occured.") removeTextFieldObserver() @@ -199,17 +199,17 @@ class ViewController : UITableViewController, UITextFieldDelegate { alertController.addAction(cancelAction) alertController.addAction(otherAction) - presentViewController(alertController, animated: true, completion: nil) + present(alertController, animated: true, completion: nil) } /// Show a custom alert. - func showCustomAlert(_: NSIndexPath) { + func showCustomAlert(_: IndexPath) { let title = "LOGIN" let message = "Input your ID and Password" let cancelButtonTitle = "Cancel" let otherButtonTitle = "Login" - customAlertController = DOAlertController(title: title, message: message, preferredStyle: .Alert) + customAlertController = DOAlertController(title: title, message: message, preferredStyle: .alert) // OverlayView customAlertController.overlayColor = UIColor(red:235/255, green:245/255, blue:255/255, alpha:0.7) @@ -220,57 +220,57 @@ class ViewController : UITableViewController, UITextFieldDelegate { customAlertController.titleTextColor = UIColor(red:241/255, green:196/255, blue:15/255, alpha:1) // Message customAlertController.messageFont = UIFont(name: "GillSans-Italic", size: 15.0) - customAlertController.messageTextColor = UIColor.whiteColor() + customAlertController.messageTextColor = UIColor.white // Cancel Button - customAlertController.buttonFont[.Cancel] = UIFont(name: "GillSans-Bold", size: 16.0) + customAlertController.buttonFont[.cancel] = UIFont(name: "GillSans-Bold", size: 16.0) // Default Button - customAlertController.buttonFont[.Default] = UIFont(name: "GillSans-Bold", size: 16.0) - customAlertController.buttonTextColor[.Default] = UIColor(red:44/255, green:62/255, blue:80/255, alpha:1) - customAlertController.buttonBgColor[.Default] = UIColor(red: 46/255, green:204/255, blue:113/255, alpha:1) - customAlertController.buttonBgColorHighlighted[.Default] = UIColor(red:64/255, green:212/255, blue:126/255, alpha:1) + customAlertController.buttonFont[.default] = UIFont(name: "GillSans-Bold", size: 16.0) + customAlertController.buttonTextColor[.default] = UIColor(red:44/255, green:62/255, blue:80/255, alpha:1) + customAlertController.buttonBgColor[.default] = UIColor(red: 46/255, green:204/255, blue:113/255, alpha:1) + customAlertController.buttonBgColorHighlighted[.default] = UIColor(red:64/255, green:212/255, blue:126/255, alpha:1) customAlertController.addTextFieldWithConfigurationHandler { textField in self.textField1 = textField - textField.placeholder = "ID" - textField.frame.size = CGSizeMake(240.0, 30.0) - textField.font = UIFont(name: "HelveticaNeue", size: 15.0) - textField.keyboardAppearance = UIKeyboardAppearance.Dark - textField.returnKeyType = UIReturnKeyType.Next + textField?.placeholder = "ID" + textField?.frame.size = CGSize(width: 240.0, height: 30.0) + textField?.font = UIFont(name: "HelveticaNeue", size: 15.0) + textField?.keyboardAppearance = UIKeyboardAppearance.dark + textField?.returnKeyType = UIReturnKeyType.next - var label:UILabel = UILabel(frame: CGRectMake(0, 0, 50, 30)) + let label:UILabel = UILabel(frame: CGRect(x: 0, y: 0, width: 50, height: 30)) label.text = "ID" label.font = UIFont(name: "GillSans-Bold", size: 15.0) - textField.leftView = label - textField.leftViewMode = UITextFieldViewMode.Always + textField?.leftView = label + textField?.leftViewMode = UITextFieldViewMode.always - textField.delegate = self + textField?.delegate = self } customAlertController.addTextFieldWithConfigurationHandler { textField in self.textField2 = textField - textField.secureTextEntry = true - textField.placeholder = "Password" - textField.frame.size = CGSizeMake(240.0, 30.0) - textField.font = UIFont(name: "HelveticaNeue", size: 15.0) - textField.keyboardAppearance = UIKeyboardAppearance.Dark - textField.returnKeyType = UIReturnKeyType.Send + textField?.isSecureTextEntry = true + textField?.placeholder = "Password" + textField?.frame.size = CGSize(width: 240.0, height: 30.0) + textField?.font = UIFont(name: "HelveticaNeue", size: 15.0) + textField?.keyboardAppearance = UIKeyboardAppearance.dark + textField?.returnKeyType = UIReturnKeyType.send - var label:UILabel = UILabel(frame: CGRectMake(0, 0, 50, 30)) + let label:UILabel = UILabel(frame: CGRect(x: 0, y: 0, width: 50, height: 30)) label.text = "PASS" label.font = UIFont(name: "GillSans-Bold", size: 15.0) - textField.leftView = label - textField.leftViewMode = UITextFieldViewMode.Always + textField?.leftView = label + textField?.leftViewMode = UITextFieldViewMode.always - textField.delegate = self + textField?.delegate = self } // Create the actions. - let cancelAction = DOAlertAction(title: cancelButtonTitle, style: .Cancel) { action in + let cancelAction = DOAlertAction(title: cancelButtonTitle, style: .cancel) { action in NSLog("The \"Custom\" alert's cancel action occured.") } - let otherAction = DOAlertAction(title: otherButtonTitle, style: .Default) { action in + let otherAction = DOAlertAction(title: otherButtonTitle, style: .default) { action in NSLog("The \"Custom\" alert's other action occured.") let textFields = self.customAlertController.textFields as? Array @@ -286,24 +286,24 @@ class ViewController : UITableViewController, UITextFieldDelegate { customAlertController.addAction(cancelAction) customAlertController.addAction(otherAction) - presentViewController(customAlertController, animated: true, completion: nil) + present(customAlertController, animated: true, completion: nil) } // MARK: DOAlertControllerStyleActionSheet Style Alerts /// Show a dialog with an "Okay" and "Cancel" button. - func showOkayCancelActionSheet(selectedIndexPath: NSIndexPath) { + func showOkayCancelActionSheet(_ selectedIndexPath: IndexPath) { let cancelButtonTitle = "Cancel" let destructiveButtonTitle = "OK" - let alertController = DOAlertController(title: nil, message: nil, preferredStyle: .ActionSheet) + let alertController = DOAlertController(title: nil, message: nil, preferredStyle: .actionSheet) // Create the actions. - let cancelAction = DOAlertAction(title: cancelButtonTitle, style: .Cancel) { action in + let cancelAction = DOAlertAction(title: cancelButtonTitle, style: .cancel) { action in NSLog("The \"Okay/Cancel\" alert action sheet's cancel action occured.") } - let destructiveAction = DOAlertAction(title: destructiveButtonTitle, style: .Destructive) { action in + let destructiveAction = DOAlertAction(title: destructiveButtonTitle, style: .destructive) { action in NSLog("The \"Okay/Cancel\" alert action sheet's destructive action occured.") } @@ -311,24 +311,24 @@ class ViewController : UITableViewController, UITextFieldDelegate { alertController.addAction(cancelAction) alertController.addAction(destructiveAction) - presentViewController(alertController, animated: true, completion: nil) + present(alertController, animated: true, completion: nil) } /// Show a dialog with two custom buttons. - func showOtherActionSheet(selectedIndexPath: NSIndexPath) { + func showOtherActionSheet(_ selectedIndexPath: IndexPath) { let title = "Other ActionSheet" let message = "A message should be a short, complete sentence." let destructiveButtonTitle = "Destructive Choice" let otherButtonTitle = "Safe Choice" - let alertController = DOAlertController(title: title, message: message, preferredStyle: .ActionSheet) + let alertController = DOAlertController(title: title, message: message, preferredStyle: .actionSheet) // Create the actions. - let destructiveAction = DOAlertAction(title: destructiveButtonTitle, style: .Destructive) { action in + let destructiveAction = DOAlertAction(title: destructiveButtonTitle, style: .destructive) { action in NSLog("The \"Other\" alert action sheet's destructive action occured.") } - let otherAction = DOAlertAction(title: otherButtonTitle, style: .Default) { action in + let otherAction = DOAlertAction(title: otherButtonTitle, style: .default) { action in NSLog("The \"Other\" alert action sheet's other action occured.") } @@ -336,18 +336,18 @@ class ViewController : UITableViewController, UITextFieldDelegate { alertController.addAction(destructiveAction) alertController.addAction(otherAction) - presentViewController(alertController, animated: true, completion: nil) + present(alertController, animated: true, completion: nil) } /// Show a custom dialog. - func showCustomActionSheet(selectedIndexPath: NSIndexPath) { + func showCustomActionSheet(_ selectedIndexPath: IndexPath) { let title = "A Short Title is Best" let message = "A message should be a short, complete sentence." let cancelButtonTitle = "Cancel" let otherButtonTitle = "Save" let destructiveButtonTitle = "Delete" - let alertController = DOAlertController(title: title, message: message, preferredStyle: .ActionSheet) + let alertController = DOAlertController(title: title, message: message, preferredStyle: .actionSheet) // OverlayView alertController.overlayColor = UIColor(red:235/255, green:245/255, blue:255/255, alpha:0.7) @@ -358,26 +358,26 @@ class ViewController : UITableViewController, UITextFieldDelegate { alertController.titleTextColor = UIColor(red:241/255, green:196/255, blue:15/255, alpha:1) // Message alertController.messageFont = UIFont(name: "GillSans-Italic", size: 15.0) - alertController.messageTextColor = UIColor.whiteColor() + alertController.messageTextColor = UIColor.white // Cancel Button - alertController.buttonFont[.Cancel] = UIFont(name: "GillSans-Bold", size: 16.0) + alertController.buttonFont[.cancel] = UIFont(name: "GillSans-Bold", size: 16.0) // Other Button - alertController.buttonFont[.Default] = UIFont(name: "GillSans-Bold", size: 16.0) + alertController.buttonFont[.default] = UIFont(name: "GillSans-Bold", size: 16.0) // Default Button - alertController.buttonFont[.Destructive] = UIFont(name: "GillSans-Bold", size: 16.0) - alertController.buttonBgColor[.Destructive] = UIColor(red: 192/255, green:57/255, blue:43/255, alpha:1) - alertController.buttonBgColorHighlighted[.Destructive] = UIColor(red:209/255, green:66/255, blue:51/255, alpha:1) + alertController.buttonFont[.destructive] = UIFont(name: "GillSans-Bold", size: 16.0) + alertController.buttonBgColor[.destructive] = UIColor(red: 192/255, green:57/255, blue:43/255, alpha:1) + alertController.buttonBgColorHighlighted[.destructive] = UIColor(red:209/255, green:66/255, blue:51/255, alpha:1) // Create the actions. - let cancelAction = DOAlertAction(title: cancelButtonTitle, style: .Cancel) { action in + let cancelAction = DOAlertAction(title: cancelButtonTitle, style: .cancel) { action in NSLog("The \"Custom\" alert action sheet's cancel action occured.") } - let otherAction = DOAlertAction(title: otherButtonTitle, style: .Default) { action in + let otherAction = DOAlertAction(title: otherButtonTitle, style: .default) { action in NSLog("The \"Custom\" alert action sheet's other action occured.") } - let destructiveAction = DOAlertAction(title: destructiveButtonTitle, style: .Destructive) { action in + let destructiveAction = DOAlertAction(title: destructiveButtonTitle, style: .destructive) { action in NSLog("The \"Custom\" alert action sheet's destructive action occured.") } @@ -386,39 +386,39 @@ class ViewController : UITableViewController, UITextFieldDelegate { alertController.addAction(otherAction) alertController.addAction(destructiveAction) - presentViewController(alertController, animated: true, completion: nil) + present(alertController, animated: true, completion: nil) } // MARK: UITextFieldTextDidChangeNotification - func handleTextFieldTextDidChangeNotification(notification: NSNotification) { + func handleTextFieldTextDidChangeNotification(_ notification: Notification) { let textField = notification.object as! UITextField // Enforce a minimum length of >= 5 characters for secure text alerts. - secureTextAlertAction!.enabled = count(textField.text) >= 5 + secureTextAlertAction!.enabled = (textField.text!.characters.count >= 5) } // MARK: UITextFieldDelegate Methods - func textFieldShouldReturn(textField: UITextField) -> Bool { + func textFieldShouldReturn(_ textField: UITextField) -> Bool { if (textField === textField1) { self.textField2?.becomeFirstResponder() } else if (textField === textField2) { customAlertAction!.handler(customAlertAction) self.textField2?.resignFirstResponder() - self.customAlertController.dismissViewControllerAnimated(true, completion: nil) + self.customAlertController.dismiss(animated: true, completion: nil) } return true } // MARK: UITableViewDelegate - override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) { + override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { let action = actionMap[indexPath.section][indexPath.row] - action(selectedIndexPath: indexPath) + action(indexPath) - tableView.deselectRowAtIndexPath(indexPath, animated: true) + tableView.deselectRow(at: indexPath, animated: true) } } diff --git a/DOAlertController-DEMO/DOAlertController-DEMOTests/DOAlertController_DEMOTests.swift b/DOAlertController-DEMO/DOAlertController-DEMOTests/DOAlertController_DEMOTests.swift old mode 100644 new mode 100755 index 2d2eabe..5b3035a --- a/DOAlertController-DEMO/DOAlertController-DEMOTests/DOAlertController_DEMOTests.swift +++ b/DOAlertController-DEMO/DOAlertController-DEMOTests/DOAlertController_DEMOTests.swift @@ -28,7 +28,7 @@ class DOAlertController_DEMOTests: XCTestCase { func testPerformanceExample() { // This is an example of a performance test case. - self.measureBlock() { + self.measure() { // Put the code you want to measure the time of here. } } diff --git a/DOAlertController-DEMO/DOAlertController-DEMOTests/Info.plist b/DOAlertController-DEMO/DOAlertController-DEMOTests/Info.plist old mode 100644 new mode 100755 index 6770f14..ba72822 --- a/DOAlertController-DEMO/DOAlertController-DEMOTests/Info.plist +++ b/DOAlertController-DEMO/DOAlertController-DEMOTests/Info.plist @@ -7,7 +7,7 @@ CFBundleExecutable $(EXECUTABLE_NAME) CFBundleIdentifier - co.devlog.$(PRODUCT_NAME:rfc1034identifier) + $(PRODUCT_BUNDLE_IDENTIFIER) CFBundleInfoDictionaryVersion 6.0 CFBundleName diff --git a/DOAlertController/DOAlertController.swift b/DOAlertController/DOAlertController.swift old mode 100644 new mode 100755 diff --git a/README.md b/README.md index 81f4a15..4c01459 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,5 @@ # DOAlertController +# Swift 3 Simple Alert View written in Swift, which can be used as a UIAlertController replacement. It supports from iOS7! It is simple and easily customizable!