diff --git a/Example/SCLAlertViewExample.xcodeproj/project.pbxproj b/Example/SCLAlertViewExample.xcodeproj/project.pbxproj index 67e5abd..d970d13 100644 --- a/Example/SCLAlertViewExample.xcodeproj/project.pbxproj +++ b/Example/SCLAlertViewExample.xcodeproj/project.pbxproj @@ -411,6 +411,7 @@ ASSETCATALOG_COMPILER_LAUNCHIMAGE_NAME = LaunchImage; EMBEDDED_CONTENT_CONTAINS_SWIFT = YES; INFOPLIST_FILE = SCLAlertViewExample/Info.plist; + IPHONEOS_DEPLOYMENT_TARGET = 8.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = "SIX-DAYS-LLC.${PRODUCT_NAME:rfc1034identifier}"; PRODUCT_NAME = "$(TARGET_NAME)"; @@ -425,6 +426,7 @@ ASSETCATALOG_COMPILER_LAUNCHIMAGE_NAME = LaunchImage; EMBEDDED_CONTENT_CONTAINS_SWIFT = YES; INFOPLIST_FILE = SCLAlertViewExample/Info.plist; + IPHONEOS_DEPLOYMENT_TARGET = 8.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = "SIX-DAYS-LLC.${PRODUCT_NAME:rfc1034identifier}"; PRODUCT_NAME = "$(TARGET_NAME)"; diff --git a/Example/SCLAlertViewExample/ViewController.swift b/Example/SCLAlertViewExample/ViewController.swift index d75d659..1883edb 100644 --- a/Example/SCLAlertViewExample/ViewController.swift +++ b/Example/SCLAlertViewExample/ViewController.swift @@ -103,7 +103,12 @@ class ViewController: UIViewController { print("Logged in") } - alert.showInfo("Login", subTitle: "") + // Add Button with Duration Status and custom Colors + alert.addButton("Duration Button", backgroundColor: UIColor.brownColor(), textColor: UIColor.yellowColor(), showDurationStatus: true) { + print("Duration Button tapped") + } + + alert.showInfo("Login", subTitle: "", duration: 10) } func firstButton() { diff --git a/SCLAlertView.xcodeproj/project.pbxproj b/SCLAlertView.xcodeproj/project.pbxproj index a58a480..9e43dcc 100644 --- a/SCLAlertView.xcodeproj/project.pbxproj +++ b/SCLAlertView.xcodeproj/project.pbxproj @@ -364,8 +364,8 @@ ENABLE_TESTABILITY = YES; INFOPLIST_FILE = SCLAlertView/Info.plist; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; - IPHONEOS_DEPLOYMENT_TARGET = 7.0; - LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; + IPHONEOS_DEPLOYMENT_TARGET = 8.0; + LD_RUNPATH_SEARCH_PATHS = ""; PRODUCT_NAME = "$(TARGET_NAME)"; SKIP_INSTALL = YES; }; @@ -381,8 +381,8 @@ ENABLE_TESTABILITY = YES; INFOPLIST_FILE = SCLAlertView/Info.plist; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; - IPHONEOS_DEPLOYMENT_TARGET = 7.0; - LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; + IPHONEOS_DEPLOYMENT_TARGET = 8.0; + LD_RUNPATH_SEARCH_PATHS = ""; PRODUCT_NAME = "$(TARGET_NAME)"; SKIP_INSTALL = YES; }; @@ -391,16 +391,13 @@ 70264F111B0F588800B32B18 /* Debug */ = { isa = XCBuildConfiguration; buildSettings = { - FRAMEWORK_SEARCH_PATHS = ( - "$(SDKROOT)/Developer/Library/Frameworks", - "$(inherited)", - ); + FRAMEWORK_SEARCH_PATHS = ""; GCC_PREPROCESSOR_DEFINITIONS = ( "DEBUG=1", "$(inherited)", ); INFOPLIST_FILE = SCLAlertViewTests/Info.plist; - LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; + LD_RUNPATH_SEARCH_PATHS = ""; PRODUCT_NAME = "$(TARGET_NAME)"; }; name = Debug; @@ -408,12 +405,9 @@ 70264F121B0F588800B32B18 /* Release */ = { isa = XCBuildConfiguration; buildSettings = { - FRAMEWORK_SEARCH_PATHS = ( - "$(SDKROOT)/Developer/Library/Frameworks", - "$(inherited)", - ); + FRAMEWORK_SEARCH_PATHS = ""; INFOPLIST_FILE = SCLAlertViewTests/Info.plist; - LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; + LD_RUNPATH_SEARCH_PATHS = ""; PRODUCT_NAME = "$(TARGET_NAME)"; }; name = Release; diff --git a/SCLAlertView/SCLAlertView.swift b/SCLAlertView/SCLAlertView.swift index 72f40aa..313ceaa 100644 --- a/SCLAlertView/SCLAlertView.swift +++ b/SCLAlertView/SCLAlertView.swift @@ -46,6 +46,10 @@ public class SCLButton: UIButton { var target:AnyObject! var selector:Selector! var action:(()->Void)! + var customBackgroundColor:UIColor? + var customTextColor:UIColor? + var initialTitle:String! + var showDurationStatus:Bool=false public init() { super.init(frame: CGRectZero) @@ -136,6 +140,8 @@ public class SCLAlertView: UIViewController { var circleBG = UIView(frame:CGRect(x:0, y:0, width:kCircleHeightBackground, height:kCircleHeightBackground)) var circleView = UIView() var circleIconView : UIView? + var duration: NSTimeInterval! + var durationStatusTimer: NSTimer! var durationTimer: NSTimer! var dismissBlock : DismissBlock? private var inputs = [UITextField]() @@ -327,8 +333,8 @@ public class SCLAlertView: UIViewController { return txt } - public func addButton(title:String, action:()->Void)->SCLButton { - let btn = addButton(title) + public func addButton(title:String, backgroundColor:UIColor? = nil, textColor:UIColor? = nil, showDurationStatus:Bool=false, action:()->Void)->SCLButton { + let btn = addButton(title, backgroundColor: backgroundColor, textColor: textColor, showDurationStatus: showDurationStatus) btn.actionType = SCLActionType.Closure btn.action = action btn.addTarget(self, action:#selector(SCLAlertView.buttonTapped(_:)), forControlEvents:.TouchUpInside) @@ -337,8 +343,8 @@ public class SCLAlertView: UIViewController { return btn } - public func addButton(title:String, target:AnyObject, selector:Selector)->SCLButton { - let btn = addButton(title) + public func addButton(title:String, backgroundColor:UIColor? = nil, textColor:UIColor? = nil, showDurationStatus:Bool = false, target:AnyObject, selector:Selector)->SCLButton { + let btn = addButton(title, backgroundColor: backgroundColor, textColor: textColor, showDurationStatus: showDurationStatus) btn.actionType = SCLActionType.Selector btn.target = target btn.selector = selector @@ -348,7 +354,7 @@ public class SCLAlertView: UIViewController { return btn } - private func addButton(title:String)->SCLButton { + private func addButton(title:String, backgroundColor:UIColor? = nil, textColor:UIColor? = nil, showDurationStatus:Bool=false)->SCLButton { // Update view height kWindowHeight += kButtonHeight // Add button @@ -356,6 +362,10 @@ public class SCLAlertView: UIViewController { btn.layer.masksToBounds = true btn.setTitle(title, forState: .Normal) btn.titleLabel?.font = UIFont(name:kButtonFont, size: 14) + btn.customBackgroundColor = backgroundColor + btn.customTextColor = textColor + btn.initialTitle = title + btn.showDurationStatus = showDurationStatus contentView.addSubview(btn) buttons.append(btn) return btn @@ -536,8 +546,7 @@ public class SCLAlertView: UIViewController { // Done button if showCloseButton { - let txt = completeText != nil ? completeText! : "Done" - addButton(txt, target:self, selector:#selector(SCLAlertView.hideView)) + addButton(completeText ?? "Done", target:self, selector:#selector(SCLAlertView.hideView)) } //hidden/show circular view based on the ui option @@ -574,14 +583,30 @@ public class SCLAlertView: UIViewController { } for btn in buttons { - btn.backgroundColor = viewColor - btn.setTitleColor(UIColorFromRGB(colorTextButton ?? 0xFFFFFF), forState:UIControlState.Normal) + if let customBackgroundColor = btn.customBackgroundColor { + // Custom BackgroundColor set + btn.backgroundColor = customBackgroundColor + } else { + // Use default BackgroundColor derived from AlertStyle + btn.backgroundColor = viewColor + } + + if let customTextColor = btn.customTextColor { + // Custom TextColor set + btn.setTitleColor(customTextColor, forState:UIControlState.Normal) + } else { + // Use default BackgroundColor derived from AlertStyle + btn.setTitleColor(UIColorFromRGB(colorTextButton ?? 0xFFFFFF), forState:UIControlState.Normal) + } } // Adding duration if duration > 0 { + self.duration = duration durationTimer?.invalidate() - durationTimer = NSTimer.scheduledTimerWithTimeInterval(duration!, target: self, selector: #selector(SCLAlertView.hideView), userInfo: nil, repeats: false) + durationTimer = NSTimer.scheduledTimerWithTimeInterval(self.duration, target: self, selector: #selector(SCLAlertView.hideView), userInfo: nil, repeats: false) + durationStatusTimer?.invalidate() + durationStatusTimer = NSTimer.scheduledTimerWithTimeInterval(1.0, target: self, selector: #selector(SCLAlertView.updateDurationStatus), userInfo: nil, repeats: true) } // Animate in the alert view @@ -598,12 +623,23 @@ public class SCLAlertView: UIViewController { return SCLAlertViewResponder(alertview: self) } + public func updateDurationStatus() { + duration = duration.advancedBy(-1) + for btn in buttons.filter({$0.showDurationStatus}) { + let txt = "\(btn.initialTitle) (\(duration))" + btn.setTitle(txt, forState: .Normal) + } + } + // Close SCLAlertView public func hideView() { UIView.animateWithDuration(0.2, animations: { self.view.alpha = 0 }, completion: { finished in + // Stop StatusTimer + self.durationStatusTimer?.invalidate() + if(self.dismissBlock != nil) { // Call completion handler when the alert is dismissed self.dismissBlock!()