From 11fb8f304c982e5b53a9ca9e3a2cd7a292b08ccd Mon Sep 17 00:00:00 2001 From: Christian Steffens Date: Sun, 1 May 2016 22:08:43 +0200 Subject: [PATCH 1/4] - Increasing Deployment Target to iOS 8 to fix the Warning regarding embedded dylibs/frameworks (they only run on iOS 8 or later) - Removing Search Paths to fix another Warning regarding non-existing search paths --- .../SCLAlertViewExample.xcodeproj/project.pbxproj | 2 ++ SCLAlertView.xcodeproj/project.pbxproj | 12 ++++++------ 2 files changed, 8 insertions(+), 6 deletions(-) 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/SCLAlertView.xcodeproj/project.pbxproj b/SCLAlertView.xcodeproj/project.pbxproj index a58a480..e1182ca 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; }; @@ -400,7 +400,7 @@ "$(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; @@ -413,7 +413,7 @@ "$(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 = Release; From e40b9be1a4c6c168962496443b10fe5cf8801ab2 Mon Sep 17 00:00:00 2001 From: Christian Steffens Date: Sun, 1 May 2016 22:10:37 +0200 Subject: [PATCH 2/4] - Removing another Search Paths to fix a Warning regarding non-existing Framework search paths --- SCLAlertView.xcodeproj/project.pbxproj | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/SCLAlertView.xcodeproj/project.pbxproj b/SCLAlertView.xcodeproj/project.pbxproj index e1182ca..9e43dcc 100644 --- a/SCLAlertView.xcodeproj/project.pbxproj +++ b/SCLAlertView.xcodeproj/project.pbxproj @@ -391,10 +391,7 @@ 70264F111B0F588800B32B18 /* Debug */ = { isa = XCBuildConfiguration; buildSettings = { - FRAMEWORK_SEARCH_PATHS = ( - "$(SDKROOT)/Developer/Library/Frameworks", - "$(inherited)", - ); + FRAMEWORK_SEARCH_PATHS = ""; GCC_PREPROCESSOR_DEFINITIONS = ( "DEBUG=1", "$(inherited)", @@ -408,10 +405,7 @@ 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 = ""; PRODUCT_NAME = "$(TARGET_NAME)"; From 57d1089812c79e39f7ab457c027f11070dbe462c Mon Sep 17 00:00:00 2001 From: Christian Steffens Date: Sun, 1 May 2016 22:33:47 +0200 Subject: [PATCH 3/4] * Draft for Duration Status in Button --- SCLAlertView/SCLAlertView.swift | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/SCLAlertView/SCLAlertView.swift b/SCLAlertView/SCLAlertView.swift index 72f40aa..8a26551 100644 --- a/SCLAlertView/SCLAlertView.swift +++ b/SCLAlertView/SCLAlertView.swift @@ -136,6 +136,9 @@ 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 durationTitle: String! + var durationStatusTimer: NSTimer! var durationTimer: NSTimer! var dismissBlock : DismissBlock? private var inputs = [UITextField]() @@ -536,8 +539,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 @@ -580,8 +582,12 @@ public class SCLAlertView: UIViewController { // Adding duration if duration > 0 { + self.duration = duration + self.durationTitle = completeText ?? "Done" 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.updateStatusView), userInfo: nil, repeats: true) } // Animate in the alert view @@ -598,12 +604,24 @@ public class SCLAlertView: UIViewController { return SCLAlertViewResponder(alertview: self) } + public func updateStatusView() { + + if let btn = buttons.last { + duration = duration.advancedBy(-1) + let txt = "\(durationTitle) (\(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!() From e08939e97cf23587b73175ba4b97b7ef9daf3453 Mon Sep 17 00:00:00 2001 From: Christian Steffens Date: Mon, 2 May 2016 21:42:50 +0200 Subject: [PATCH 4/4] + Adding custom Background and Text Color for Buttons + Adding showDurationStatus to Buttons --- .../SCLAlertViewExample/ViewController.swift | 7 ++- SCLAlertView/SCLAlertView.swift | 48 +++++++++++++------ 2 files changed, 39 insertions(+), 16 deletions(-) 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/SCLAlertView.swift b/SCLAlertView/SCLAlertView.swift index 8a26551..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) @@ -137,7 +141,6 @@ public class SCLAlertView: UIViewController { var circleView = UIView() var circleIconView : UIView? var duration: NSTimeInterval! - var durationTitle: String! var durationStatusTimer: NSTimer! var durationTimer: NSTimer! var dismissBlock : DismissBlock? @@ -330,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) @@ -340,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 @@ -351,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 @@ -359,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 @@ -576,18 +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 - self.durationTitle = completeText ?? "Done" durationTimer?.invalidate() 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.updateStatusView), userInfo: nil, repeats: true) + durationStatusTimer = NSTimer.scheduledTimerWithTimeInterval(1.0, target: self, selector: #selector(SCLAlertView.updateDurationStatus), userInfo: nil, repeats: true) } // Animate in the alert view @@ -604,11 +623,10 @@ public class SCLAlertView: UIViewController { return SCLAlertViewResponder(alertview: self) } - public func updateStatusView() { - - if let btn = buttons.last { - duration = duration.advancedBy(-1) - let txt = "\(durationTitle) (\(duration))" + public func updateDurationStatus() { + duration = duration.advancedBy(-1) + for btn in buttons.filter({$0.showDurationStatus}) { + let txt = "\(btn.initialTitle) (\(duration))" btn.setTitle(txt, forState: .Normal) } }