From 3fb59cf3e58106446351997024ae526fa7a15611 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?PRSolu=C3=A7=C3=B5es?= Date: Mon, 16 Oct 2017 14:52:37 -0200 Subject: [PATCH] Added activity animation as appearance parameter and added button for wait example (#343) * added activity animation as appearance parameter and added button for wait example * added activity animation as appearance parameter and added button for wait example --- Example/SCLAlertViewExample/Main.storyboard | 94 ++++++++++--------- .../SCLAlertViewExample/ViewController.swift | 33 ++++++- SCLAlertView/SCLAlertView.swift | 22 +++-- 3 files changed, 97 insertions(+), 52 deletions(-) diff --git a/Example/SCLAlertViewExample/Main.storyboard b/Example/SCLAlertViewExample/Main.storyboard index 0d5239e..cd9bae5 100644 --- a/Example/SCLAlertViewExample/Main.storyboard +++ b/Example/SCLAlertViewExample/Main.storyboard @@ -1,8 +1,12 @@ - - + + + + + - + + @@ -14,108 +18,108 @@ - + + - + - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + - - - - - - diff --git a/Example/SCLAlertViewExample/ViewController.swift b/Example/SCLAlertViewExample/ViewController.swift index b5e61de..ecbc19c 100644 --- a/Example/SCLAlertViewExample/ViewController.swift +++ b/Example/SCLAlertViewExample/ViewController.swift @@ -58,7 +58,7 @@ class ViewController: UIViewController { @IBAction func showInfo(_ sender: AnyObject) { _ = SCLAlertView().showInfo(kInfoTitle, subTitle: kSubtitle) } - + @IBAction func showEdit(_ sender: AnyObject) { let appearance = SCLAlertView.SCLAppearance(showCloseButton: true) let alert = SCLAlertView(appearance: appearance) @@ -69,6 +69,37 @@ class ViewController: UIViewController { _ = alert.showEdit(kInfoTitle, subTitle:kSubtitle) } + @IBAction func showWait(_ sender: AnyObject) { + let appearance = SCLAlertView.SCLAppearance( + showCloseButton: false + ) + + let alert = SCLAlertView(appearance: appearance).showWait("Download", subTitle: "Processing...", closeButtonTitle: nil, timeout: nil, colorStyle: nil, colorTextButton: 0xFFFFFF, circleIconImage: nil, animationStyle: SCLAnimationStyle.topToBottom) + + DispatchQueue.main.asyncAfter(deadline: .now() + 2.0) { + alert.setSubTitle("Progress: 10%") + + DispatchQueue.main.asyncAfter(deadline: .now() + 2.0) { + alert.setSubTitle("Progress: 30%") + + DispatchQueue.main.asyncAfter(deadline: .now() + 2.0) { + alert.setSubTitle("Progress: 50%") + + DispatchQueue.main.asyncAfter(deadline: .now() + 2.0) { + alert.setSubTitle("Progress: 70%") + + DispatchQueue.main.asyncAfter(deadline: .now() + 2.0) { + alert.setSubTitle("Progress: 90%") + + DispatchQueue.main.asyncAfter(deadline: .now() + 2.0) { + alert.close() + } + } + } + } + } + } + } @IBAction func showCustomSubview(_ sender: AnyObject) { // Create custom Appearance Configuration diff --git a/SCLAlertView/SCLAlertView.swift b/SCLAlertView/SCLAlertView.swift index c096b00..24ca4fa 100644 --- a/SCLAlertView/SCLAlertView.swift +++ b/SCLAlertView/SCLAlertView.swift @@ -175,10 +175,14 @@ open class SCLAlertView: UIViewController { var buttonCornerRadius : CGFloat var dynamicAnimatorActive : Bool var buttonsLayout: SCLAlertButtonLayout + // Actions var hideWhenBackgroundViewIsTapped: Bool - public init(kDefaultShadowOpacity: CGFloat = 0.7, kCircleTopPosition: CGFloat = 0.0, kCircleBackgroundTopPosition: CGFloat = 6.0, kCircleHeight: CGFloat = 56.0, kCircleIconHeight: CGFloat = 20.0, kTitleTop:CGFloat = 30.0, kTitleHeight:CGFloat = 25.0, kWindowWidth: CGFloat = 240.0, kWindowHeight: CGFloat = 178.0, kTextHeight: CGFloat = 90.0, kTextFieldHeight: CGFloat = 45.0, kTextViewdHeight: CGFloat = 80.0, kButtonHeight: CGFloat = 45.0, kTitleFont: UIFont = UIFont.systemFont(ofSize: 20), kTitleMinimumScaleFactor: CGFloat = 1.0, kTextFont: UIFont = UIFont.systemFont(ofSize: 14), kButtonFont: UIFont = UIFont.boldSystemFont(ofSize: 14), showCloseButton: Bool = true, showCircularIcon: Bool = true, shouldAutoDismiss: Bool = true, contentViewCornerRadius: CGFloat = 5.0, fieldCornerRadius: CGFloat = 3.0, buttonCornerRadius: CGFloat = 3.0, hideWhenBackgroundViewIsTapped: Bool = false, circleBackgroundColor: UIColor = UIColor.white, contentViewColor: UIColor = UIColorFromRGB(0xFFFFFF), contentViewBorderColor: UIColor = UIColorFromRGB(0xCCCCCC), titleColor: UIColor = UIColorFromRGB(0x4D4D4D), dynamicAnimatorActive: Bool = false, disableTapGesture: Bool = false, buttonsLayout: SCLAlertButtonLayout = .vertical) { + // Activity indicator + var activityIndicatorStyle: UIActivityIndicatorViewStyle + + public init(kDefaultShadowOpacity: CGFloat = 0.7, kCircleTopPosition: CGFloat = 0.0, kCircleBackgroundTopPosition: CGFloat = 6.0, kCircleHeight: CGFloat = 56.0, kCircleIconHeight: CGFloat = 20.0, kTitleTop:CGFloat = 30.0, kTitleHeight:CGFloat = 25.0, kWindowWidth: CGFloat = 240.0, kWindowHeight: CGFloat = 178.0, kTextHeight: CGFloat = 90.0, kTextFieldHeight: CGFloat = 45.0, kTextViewdHeight: CGFloat = 80.0, kButtonHeight: CGFloat = 45.0, kTitleFont: UIFont = UIFont.systemFont(ofSize: 20), kTitleMinimumScaleFactor: CGFloat = 1.0, kTextFont: UIFont = UIFont.systemFont(ofSize: 14), kButtonFont: UIFont = UIFont.boldSystemFont(ofSize: 14), showCloseButton: Bool = true, showCircularIcon: Bool = true, shouldAutoDismiss: Bool = true, contentViewCornerRadius: CGFloat = 5.0, fieldCornerRadius: CGFloat = 3.0, buttonCornerRadius: CGFloat = 3.0, hideWhenBackgroundViewIsTapped: Bool = false, circleBackgroundColor: UIColor = UIColor.white, contentViewColor: UIColor = UIColorFromRGB(0xFFFFFF), contentViewBorderColor: UIColor = UIColorFromRGB(0xCCCCCC), titleColor: UIColor = UIColorFromRGB(0x4D4D4D), dynamicAnimatorActive: Bool = false, disableTapGesture: Bool = false, buttonsLayout: SCLAlertButtonLayout = .vertical, activityIndicatorStyle: UIActivityIndicatorViewStyle = .white) { self.kDefaultShadowOpacity = kDefaultShadowOpacity self.kCircleTopPosition = kCircleTopPosition @@ -214,6 +218,8 @@ open class SCLAlertView: UIViewController { self.hideWhenBackgroundViewIsTapped = hideWhenBackgroundViewIsTapped self.dynamicAnimatorActive = dynamicAnimatorActive self.buttonsLayout = buttonsLayout + + self.activityIndicatorStyle = activityIndicatorStyle } mutating func setkWindowHeight(_ kWindowHeight:CGFloat) { @@ -481,9 +487,11 @@ open class SCLAlertView: UIViewController { txt.layer.masksToBounds = true txt.layer.borderWidth = 1.0 + if title != nil { txt.placeholder = title! } + contentView.addSubview(txt) inputs.append(txt) return txt @@ -532,6 +540,7 @@ open class SCLAlertView: UIViewController { fileprivate func addButton(_ title:String, backgroundColor:UIColor? = nil, textColor:UIColor? = nil, showTimeout:SCLButton.ShowTimeoutConfiguration? = nil)->SCLButton { // Update view height appearance.setkWindowHeight(appearance.kWindowHeight + appearance.kButtonHeight) + // Add button let btn = SCLButton() btn.layer.masksToBounds = true @@ -586,17 +595,18 @@ open class SCLAlertView: UIViewController { guard let endKeyBoardFrame = (userInfo[UIKeyboardFrameEndUserInfoKey] as? NSValue)?.cgRectValue.minY else {return} if tmpContentViewFrameOrigin == nil { - tmpContentViewFrameOrigin = self.contentView.frame.origin + tmpContentViewFrameOrigin = self.contentView.frame.origin } if tmpCircleViewFrameOrigin == nil { - tmpCircleViewFrameOrigin = self.circleBG.frame.origin + tmpCircleViewFrameOrigin = self.circleBG.frame.origin } var newContentViewFrameY = self.contentView.frame.maxY - endKeyBoardFrame if newContentViewFrameY < 0 { newContentViewFrameY = 0 } + let newBallViewFrameY = self.circleBG.frame.origin.y - newContentViewFrameY self.contentView.frame.origin.y -= newContentViewFrameY self.circleBG.frame.origin.y = newBallViewFrameY @@ -630,8 +640,6 @@ open class SCLAlertView: UIViewController { // showCustom(view, title, subTitle, UIColor, UIImage) @discardableResult open func showCustom(_ title: String, subTitle: String, color: UIColor, icon: UIImage, closeButtonTitle:String?=nil, timeout:SCLTimeoutConfiguration?=nil, colorStyle: UInt=SCLAlertViewStyle.success.defaultColorInt, colorTextButton: UInt=0xFFFFFF, circleIconImage: UIImage? = nil, animationStyle: SCLAnimationStyle = .topToBottom) -> SCLAlertViewResponder { - - var red: CGFloat = 0, green: CGFloat = 0, blue: CGFloat = 0, alpha: CGFloat = 0 color.getRed(&red, green: &green, blue: &blue, alpha: &alpha) @@ -711,6 +719,7 @@ open class SCLAlertView: UIViewController { var iconImage: UIImage? let colorInt = colorStyle ?? style.defaultColorInt viewColor = UIColorFromRGB(colorInt) + // Icon style switch style { case .success: @@ -777,9 +786,10 @@ open class SCLAlertView: UIViewController { // Alert view colour and images circleView.backgroundColor = viewColor + // Spinner / icon if style == .wait { - let indicator = UIActivityIndicatorView(activityIndicatorStyle: .whiteLarge) + let indicator = UIActivityIndicatorView(activityIndicatorStyle: appearance.activityIndicatorStyle) indicator.startAnimating() circleIconView = indicator }