Guest User

SCLAClass

a guest
Sep 16th, 2016
241
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Swift 54.27 KB | None | 0 0
  1.     //
  2. //  SCLAlertView.swift
  3. //  SCLAlertView Example
  4. //
  5. //  Created by Viktor Radchenko on 6/5/14.
  6. //  Copyright (c) 2014 Viktor Radchenko. All rights reserved.
  7. //
  8.  
  9. import Foundation
  10. import UIKit
  11. fileprivate func < <T : Comparable>(lhs: T?, rhs: T?) -> Bool {
  12.   switch (lhs, rhs) {
  13.   case let (l?, r?):
  14.     return l < r
  15.   case (nil, _?):
  16.     return true
  17.   default:
  18.     return false
  19.   }
  20. }
  21.  
  22. fileprivate func > <T : Comparable>(lhs: T?, rhs: T?) -> Bool {
  23.   switch (lhs, rhs) {
  24.   case let (l?, r?):
  25.     return l > r
  26.   default:
  27.     return rhs < lhs
  28.   }
  29. }
  30.  
  31.  
  32. // Pop Up Styles
  33. public enum SCLAlertViewStyle {
  34.     case success, error, notice, warning, info, edit, wait
  35.    
  36.     var defaultColorInt: UInt {
  37.         switch self {
  38.         case .success:
  39.             return 0x22B573
  40.         case .error:
  41.             return 0xC1272D
  42.         case .notice:
  43.             return 0x727375
  44.         case .warning:
  45.             return 0xFFD110
  46.         case .info:
  47.             return 0x2866BF
  48.         case .edit:
  49.             return 0xA429FF
  50.         case .wait:
  51.             return 0xD62DA5
  52.         }
  53.        
  54.     }
  55.  
  56. }
  57.  
  58. // Animation Styles
  59. public enum SCLAnimationStyle {
  60.     case noAnimation, topToBottom, bottomToTop, leftToRight, rightToLeft
  61. }
  62.  
  63. // Action Types
  64. public enum SCLActionType {
  65.     case none, selector, closure
  66. }
  67.  
  68. // Button sub-class
  69. open class SCLButton: UIButton {
  70.     var actionType = SCLActionType.none
  71.     var target:AnyObject!
  72.     var selector:Selector!
  73.     var action:(()->Void)!
  74.     var customBackgroundColor:UIColor?
  75.     var customTextColor:UIColor?
  76.     var initialTitle:String!
  77.     var showDurationStatus:Bool=false
  78.    
  79.     public init() {
  80.         super.init(frame: CGRect.zero)
  81.     }
  82.    
  83.     required public init?(coder aDecoder: NSCoder) {
  84.         super.init(coder:aDecoder)
  85.     }
  86.    
  87.     override public init(frame:CGRect) {
  88.         super.init(frame:frame)
  89.     }
  90. }
  91.  
  92. // Allow alerts to be closed/renamed in a chainable manner
  93. // Example: SCLAlertView().showSuccess(self, title: "Test", subTitle: "Value").close()
  94. open class SCLAlertViewResponder {
  95.     let alertview: SCLAlertView
  96.    
  97.     // Initialisation and Title/Subtitle/Close functions
  98.     public init(alertview: SCLAlertView) {
  99.         self.alertview = alertview
  100.     }
  101.    
  102.     open func setTitle(_ title: String) {
  103.         self.alertview.labelTitle.text = title
  104.     }
  105.    
  106.     open func setSubTitle(_ subTitle: String) {
  107.         self.alertview.viewText.text = subTitle
  108.     }
  109.    
  110.     open func close() {
  111.         self.alertview.hideView()
  112.     }
  113.    
  114.     open func setDismissBlock(_ dismissBlock: @escaping DismissBlock) {
  115.         self.alertview.dismissBlock = dismissBlock
  116.     }
  117. }
  118.  
  119. let kCircleHeightBackground: CGFloat = 62.0
  120.  
  121. public typealias DismissBlock = () -> Void
  122.  
  123. // The Main Class
  124. open class SCLAlertView: UIViewController {
  125.    
  126.     public struct SCLAppearance {
  127.         let kDefaultShadowOpacity: CGFloat
  128.         let kCircleTopPosition: CGFloat
  129.         let kCircleBackgroundTopPosition: CGFloat
  130.         let kCircleHeight: CGFloat
  131.         let kCircleIconHeight: CGFloat
  132.         let kTitleTop:CGFloat
  133.         let kTitleHeight:CGFloat
  134.         let kWindowWidth: CGFloat
  135.         var kWindowHeight: CGFloat
  136.         var kTextHeight: CGFloat
  137.         let kTextFieldHeight: CGFloat
  138.         let kTextViewdHeight: CGFloat
  139.         let kButtonHeight: CGFloat
  140.         let contentViewColor: UIColor
  141.         let contentViewBorderColor: UIColor
  142.         let titleColor: UIColor
  143.        
  144.         // Fonts
  145.         let kTitleFont: UIFont
  146.         let kTextFont: UIFont
  147.         let kButtonFont: UIFont
  148.        
  149.         // UI Options
  150.         var showCloseButton: Bool
  151.         var showCircularIcon: Bool
  152.         var shouldAutoDismiss: Bool // Set this false to 'Disable' Auto hideView when SCLButton is tapped
  153.         var contentViewCornerRadius : CGFloat
  154.         var fieldCornerRadius : CGFloat
  155.         var buttonCornerRadius : CGFloat
  156.        
  157.         // Actions
  158.         var hideWhenBackgroundViewIsTapped: Bool
  159.        
  160.         public init(kDefaultShadowOpacity: CGFloat = 0.7, kCircleTopPosition: CGFloat = -12.0, kCircleBackgroundTopPosition: CGFloat = -15.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), 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, contentViewColor: UIColor = UIColorFromRGB(0xFFFFFF), contentViewBorderColor: UIColor = UIColorFromRGB(0xCCCCCC), titleColor: UIColor = UIColorFromRGB(0x4D4D4D)) {
  161.            
  162.             self.kDefaultShadowOpacity = kDefaultShadowOpacity
  163.             self.kCircleTopPosition = kCircleTopPosition
  164.             self.kCircleBackgroundTopPosition = kCircleBackgroundTopPosition
  165.             self.kCircleHeight = kCircleHeight
  166.             self.kCircleIconHeight = kCircleIconHeight
  167.             self.kTitleTop = kTitleTop
  168.             self.kTitleHeight = kTitleHeight
  169.             self.kWindowWidth = kWindowWidth
  170.             self.kWindowHeight = kWindowHeight
  171.             self.kTextHeight = kTextHeight
  172.             self.kTextFieldHeight = kTextFieldHeight
  173.             self.kTextViewdHeight = kTextViewdHeight
  174.             self.kButtonHeight = kButtonHeight
  175.             self.contentViewColor = contentViewColor
  176.             self.contentViewBorderColor = contentViewBorderColor
  177.             self.titleColor = titleColor
  178.            
  179.             self.kTitleFont = kTitleFont
  180.             self.kTextFont = kTextFont
  181.             self.kButtonFont = kButtonFont
  182.            
  183.             self.showCloseButton = showCloseButton
  184.             self.showCircularIcon = showCircularIcon
  185.             self.shouldAutoDismiss = shouldAutoDismiss
  186.             self.contentViewCornerRadius = contentViewCornerRadius
  187.             self.fieldCornerRadius = fieldCornerRadius
  188.             self.buttonCornerRadius = buttonCornerRadius
  189.            
  190.             self.hideWhenBackgroundViewIsTapped = hideWhenBackgroundViewIsTapped
  191.         }
  192.        
  193.         mutating func setkWindowHeight(_ kWindowHeight:CGFloat) {
  194.             self.kWindowHeight = kWindowHeight
  195.         }
  196.        
  197.         mutating func setkTextHeight(_ kTextHeight:CGFloat) {
  198.             self.kTextHeight = kTextHeight
  199.         }
  200.     }
  201.    
  202.     var appearance: SCLAppearance!
  203.    
  204.     // UI Colour
  205.     var viewColor = UIColor()
  206.    
  207.     // UI Options
  208.     open var iconTintColor: UIColor?
  209.     open var customSubview : UIView?
  210.    
  211.  
  212.    
  213.     // Members declaration
  214.     var baseView = UIView()
  215.     var labelTitle = UILabel()
  216.     var viewText = UITextView()
  217.     var contentView = UIView()
  218.     var circleBG = UIView(frame:CGRect(x:0, y:0, width:kCircleHeightBackground, height:kCircleHeightBackground))
  219.     var circleView = UIView()
  220.     var circleIconView : UIView?
  221.     var duration: TimeInterval!
  222.     var durationStatusTimer: Timer!
  223.     var durationTimer: Timer!
  224.     var dismissBlock : DismissBlock?
  225.     fileprivate var inputs = [UITextField]()
  226.     fileprivate var input = [UITextView]()
  227.     internal var buttons = [SCLButton]()
  228.     fileprivate var selfReference: SCLAlertView?
  229.    
  230.     public init(appearance: SCLAppearance) {
  231.         self.appearance = appearance
  232.         super.init(nibName:nil, bundle:nil)
  233.         setup()
  234.     }
  235.    
  236.     required public init?(coder aDecoder: NSCoder) {
  237.         fatalError("NSCoding not supported")
  238.     }
  239.    
  240.     required public init() {
  241.         appearance = SCLAppearance()
  242.         super.init(nibName:nil, bundle:nil)
  243.         setup()
  244.     }
  245.    
  246.     override public init(nibName nibNameOrNil: String?, bundle nibBundleOrNil: Bundle?) {
  247.         appearance = SCLAppearance()
  248.         super.init(nibName:nibNameOrNil, bundle:nibBundleOrNil)
  249.     }
  250.    
  251.     fileprivate func setup() {
  252.         // Set up main view
  253.         view.frame = UIScreen.main.bounds
  254.         view.autoresizingMask = [UIViewAutoresizing.flexibleHeight, UIViewAutoresizing.flexibleWidth]
  255.         view.backgroundColor = UIColor(red:0, green:0, blue:0, alpha:appearance.kDefaultShadowOpacity)
  256.         view.addSubview(baseView)
  257.         // Base View
  258.         baseView.frame = view.frame
  259.         baseView.addSubview(contentView)
  260.         // Content View
  261.         contentView.layer.cornerRadius = appearance.contentViewCornerRadius
  262.         contentView.layer.masksToBounds = true
  263.         contentView.layer.borderWidth = 0.5
  264.         contentView.addSubview(labelTitle)
  265.         contentView.addSubview(viewText)
  266.         // Circle View
  267.         circleBG.backgroundColor = UIColor.white
  268.         circleBG.layer.cornerRadius = circleBG.frame.size.height / 2
  269.         baseView.addSubview(circleBG)
  270.         circleBG.addSubview(circleView)
  271.         let x = (kCircleHeightBackground - appearance.kCircleHeight) / 2
  272.         circleView.frame = CGRect(x:x, y:x, width:appearance.kCircleHeight, height:appearance.kCircleHeight)
  273.         circleView.layer.cornerRadius = circleView.frame.size.height / 2
  274.         // Title
  275.         labelTitle.numberOfLines = 1
  276.         labelTitle.textAlignment = .center
  277.         labelTitle.font = appearance.kTitleFont
  278.         labelTitle.frame = CGRect(x:12, y:appearance.kTitleTop, width: appearance.kWindowWidth - 24, height:appearance.kTitleHeight)
  279.         // View text
  280.         viewText.isEditable = false
  281.         viewText.textAlignment = .center
  282.         viewText.textContainerInset = UIEdgeInsets.zero
  283.         viewText.textContainer.lineFragmentPadding = 0;
  284.         viewText.font = appearance.kTextFont
  285.         // Colours
  286.         contentView.backgroundColor = appearance.contentViewColor
  287.         viewText.backgroundColor = appearance.contentViewColor
  288.         labelTitle.textColor = appearance.titleColor
  289.         viewText.textColor = appearance.titleColor
  290.         contentView.layer.borderColor = appearance.contentViewBorderColor.cgColor
  291.         //Gesture Recognizer for tapping outside the textinput
  292.         let tapGesture = UITapGestureRecognizer(target: self, action: #selector(SCLAlertView.tapped(_:)))
  293.         tapGesture.numberOfTapsRequired = 1
  294.         self.view.addGestureRecognizer(tapGesture)
  295.     }
  296.    
  297.     override open func viewWillLayoutSubviews() {
  298.         super.viewWillLayoutSubviews()
  299.         let rv = UIApplication.shared.keyWindow! as UIWindow
  300.         let sz = rv.frame.size
  301.        
  302.         // Set background frame
  303.         view.frame.size = sz
  304.        
  305.         // computing the right size to use for the textView
  306.         let maxHeight = sz.height - 100 // max overall height
  307.         var consumedHeight = CGFloat(0)
  308.         consumedHeight += appearance.kTitleTop + appearance.kTitleHeight
  309.         consumedHeight += 14
  310.         consumedHeight += appearance.kButtonHeight * CGFloat(buttons.count)
  311.         consumedHeight += appearance.kTextFieldHeight * CGFloat(inputs.count)
  312.         consumedHeight += appearance.kTextViewdHeight * CGFloat(input.count)
  313.         let maxViewTextHeight = maxHeight - consumedHeight
  314.         let viewTextWidth = appearance.kWindowWidth - 24
  315.         var viewTextHeight = appearance.kTextHeight
  316.        
  317.         // Check if there is a custom subview and add it over the textview
  318.         if let customSubview = customSubview {
  319.             viewTextHeight = min(customSubview.frame.height, maxViewTextHeight)
  320.             viewText.text = ""
  321.             viewText.addSubview(customSubview)
  322.         } else {
  323.             // computing the right size to use for the textView
  324.             let suggestedViewTextSize = viewText.sizeThatFits(CGSize(width: viewTextWidth, height: CGFloat.greatestFiniteMagnitude))
  325.             viewTextHeight = min(suggestedViewTextSize.height, maxViewTextHeight)
  326.            
  327.             // scroll management
  328.             if (suggestedViewTextSize.height > maxViewTextHeight) {
  329.                 viewText.isScrollEnabled = true
  330.             } else {
  331.                 viewText.isScrollEnabled = false
  332.             }
  333.         }
  334.        
  335.         let windowHeight = consumedHeight + viewTextHeight
  336.         // Set frames
  337.         var x = (sz.width - appearance.kWindowWidth) / 2
  338.         var y = (sz.height - windowHeight - (appearance.kCircleHeight / 8)) / 2
  339.         contentView.frame = CGRect(x:x, y:y, width:appearance.kWindowWidth, height:windowHeight)
  340.         contentView.layer.cornerRadius = appearance.contentViewCornerRadius
  341.         y -= kCircleHeightBackground * 0.6
  342.         x = (sz.width - kCircleHeightBackground) / 2
  343.         circleBG.frame = CGRect(x:x, y:y+6, width:kCircleHeightBackground, height:kCircleHeightBackground)
  344.        
  345.         //adjust Title frame based on circularIcon show/hide flag
  346.         let titleOffset : CGFloat = appearance.showCircularIcon ? 0.0 : -12.0
  347.         labelTitle.frame = labelTitle.frame.offsetBy(dx: 0, dy: titleOffset)
  348.        
  349.         // Subtitle
  350.         y = appearance.kTitleTop + appearance.kTitleHeight + titleOffset
  351.         viewText.frame = CGRect(x:12, y:y, width: appearance.kWindowWidth - 24, height:appearance.kTextHeight)
  352.         viewText.frame = CGRect(x:12, y:y, width: viewTextWidth, height:viewTextHeight)
  353.         // Text fields
  354.         y += viewTextHeight + 14.0
  355.         for txt in inputs {
  356.             txt.frame = CGRect(x:12, y:y, width:appearance.kWindowWidth - 24, height:30)
  357.             txt.layer.cornerRadius = appearance.fieldCornerRadius
  358.             y += appearance.kTextFieldHeight
  359.         }
  360.         for txt in input {
  361.             txt.frame = CGRect(x:12, y:y, width:appearance.kWindowWidth - 24, height:70)
  362.             //txt.layer.cornerRadius = fieldCornerRadius
  363.             y += appearance.kTextViewdHeight
  364.         }
  365.         // Buttons
  366.         for btn in buttons {
  367.             btn.frame = CGRect(x:12, y:y, width:appearance.kWindowWidth - 24, height:35)
  368.             btn.layer.cornerRadius = appearance.buttonCornerRadius
  369.             y += appearance.kButtonHeight
  370.         }
  371.     }
  372.    
  373.     override open func viewDidAppear(_ animated: Bool) {
  374.         super.viewDidAppear(animated)
  375.         NotificationCenter.default.addObserver(self, selector: #selector(SCLAlertView.keyboardWillShow(_:)), name:NSNotification.Name.UIKeyboardWillShow, object: nil);
  376.         NotificationCenter.default.addObserver(self, selector: #selector(SCLAlertView.keyboardWillHide(_:)), name:NSNotification.Name.UIKeyboardWillHide, object: nil);
  377.     }
  378.    
  379.     override open func viewDidDisappear(_ animated: Bool) {
  380.         super.viewDidDisappear(animated)
  381.         NotificationCenter.default.removeObserver(NSNotification.Name.UIKeyboardWillShow)
  382.         NotificationCenter.default.removeObserver(NSNotification.Name.UIKeyboardWillHide)
  383.     }
  384.    
  385.     override open func touchesEnded(_ touches:Set<UITouch>, with event:UIEvent?) {
  386.         if event?.touches(for: view)?.count > 0 {
  387.             view.endEditing(true)
  388.         }
  389.     }
  390.    
  391.     open func addTextField(_ title:String?=nil)->UITextField {
  392.         // Update view height
  393.         appearance.setkWindowHeight(appearance.kWindowHeight + appearance.kTextFieldHeight)
  394.         // Add text field
  395.         let txt = UITextField()
  396.         txt.borderStyle = UITextBorderStyle.roundedRect
  397.         txt.font = appearance.kTextFont
  398.         txt.autocapitalizationType = UITextAutocapitalizationType.words
  399.         txt.clearButtonMode = UITextFieldViewMode.whileEditing
  400.         txt.layer.masksToBounds = true
  401.         txt.layer.borderWidth = 1.0
  402.         if title != nil {
  403.             txt.placeholder = title!
  404.         }
  405.         contentView.addSubview(txt)
  406.         inputs.append(txt)
  407.         return txt
  408.     }
  409.    
  410.     open func addTextView()->UITextView {
  411.         // Update view height
  412.         appearance.setkWindowHeight(appearance.kWindowHeight + appearance.kTextViewdHeight)
  413.         // Add text view
  414.         let txt = UITextView()
  415.         // No placeholder with UITextView but you can use KMPlaceholderTextView library
  416.         txt.font = appearance.kTextFont
  417.         //txt.autocapitalizationType = UITextAutocapitalizationType.Words
  418.         //txt.clearButtonMode = UITextFieldViewMode.WhileEditing
  419.         txt.layer.masksToBounds = true
  420.         txt.layer.borderWidth = 1.0
  421.         contentView.addSubview(txt)
  422.         input.append(txt)
  423.         return txt
  424.     }
  425.    
  426.     open func addButton(_ title:String, backgroundColor:UIColor? = nil, textColor:UIColor? = nil, showDurationStatus:Bool=false, action:@escaping ()->Void)->SCLButton {
  427.         let btn = addButton(title, backgroundColor: backgroundColor, textColor: textColor, showDurationStatus: showDurationStatus)
  428.         btn.actionType = SCLActionType.closure
  429.         btn.action = action
  430.         btn.addTarget(self, action:#selector(SCLAlertView.buttonTapped(_:)), for:.touchUpInside)
  431.         btn.addTarget(self, action:#selector(SCLAlertView.buttonTapDown(_:)), for:[.touchDown, .touchDragEnter])
  432.         btn.addTarget(self, action:#selector(SCLAlertView.buttonRelease(_:)), for:[.touchUpInside, .touchUpOutside, .touchCancel, .touchDragOutside] )
  433.         return btn
  434.     }
  435.    
  436.     open func addButton(_ title:String, backgroundColor:UIColor? = nil, textColor:UIColor? = nil, showDurationStatus:Bool = false, target:AnyObject, selector:Selector)->SCLButton {
  437.         let btn = addButton(title, backgroundColor: backgroundColor, textColor: textColor, showDurationStatus: showDurationStatus)
  438.         btn.actionType = SCLActionType.selector
  439.         btn.target = target
  440.         btn.selector = selector
  441.         btn.addTarget(self, action:#selector(SCLAlertView.buttonTapped(_:)), for:.touchUpInside)
  442.         btn.addTarget(self, action:#selector(SCLAlertView.buttonTapDown(_:)), for:[.touchDown, .touchDragEnter])
  443.         btn.addTarget(self, action:#selector(SCLAlertView.buttonRelease(_:)), for:[.touchUpInside, .touchUpOutside, .touchCancel, .touchDragOutside] )
  444.         return btn
  445.     }
  446.    
  447.     fileprivate func addButton(_ title:String, backgroundColor:UIColor? = nil, textColor:UIColor? = nil, showDurationStatus:Bool=false)->SCLButton {
  448.         // Update view height
  449.         appearance.setkWindowHeight(appearance.kWindowHeight + appearance.kButtonHeight)
  450.         // Add button
  451.         let btn = SCLButton()
  452.         btn.layer.masksToBounds = true
  453.         btn.setTitle(title, for: UIControlState())
  454.         btn.titleLabel?.font = appearance.kButtonFont
  455.         btn.customBackgroundColor = backgroundColor
  456.         btn.customTextColor = textColor
  457.         btn.initialTitle = title
  458.         btn.showDurationStatus = showDurationStatus
  459.         contentView.addSubview(btn)
  460.         buttons.append(btn)
  461.         return btn
  462.     }
  463.    
  464.     func buttonTapped(_ btn:SCLButton) {
  465.         if btn.actionType == SCLActionType.closure {
  466.             btn.action()
  467.         } else if btn.actionType == SCLActionType.selector {
  468.             let ctrl = UIControl()
  469.             ctrl.sendAction(btn.selector, to:btn.target, for:nil)
  470.         } else {
  471.             print("Unknow action type for button")
  472.         }
  473.        
  474.         if(self.view.alpha != 0.0 && appearance.shouldAutoDismiss){ hideView() }
  475.     }
  476.    
  477.    
  478.     func buttonTapDown(_ btn:SCLButton) {
  479.         var hue : CGFloat = 0
  480.         var saturation : CGFloat = 0
  481.         var brightness : CGFloat = 0
  482.         var alpha : CGFloat = 0
  483.         let pressBrightnessFactor = 0.85
  484.         btn.backgroundColor?.getHue(&hue, saturation: &saturation, brightness: &brightness, alpha: &alpha)
  485.         brightness = brightness * CGFloat(pressBrightnessFactor)
  486.         btn.backgroundColor = UIColor(hue: hue, saturation: saturation, brightness: brightness, alpha: alpha)
  487.     }
  488.    
  489.     func buttonRelease(_ btn:SCLButton) {
  490.         btn.backgroundColor = btn.customBackgroundColor ?? viewColor
  491.     }
  492.    
  493.     var tmpContentViewFrameOrigin: CGPoint?
  494.     var tmpCircleViewFrameOrigin: CGPoint?
  495.     var keyboardHasBeenShown:Bool = false
  496.    
  497.     func keyboardWillShow(_ notification: Notification) {
  498.         keyboardHasBeenShown = true
  499.        
  500.         guard let userInfo = (notification as NSNotification).userInfo else {return}
  501.         guard let endKeyBoardFrame = (userInfo[UIKeyboardFrameEndUserInfoKey] as AnyObject? )?.cgRectValue.minY else {return}
  502.        
  503.         if tmpContentViewFrameOrigin == nil {
  504.         tmpContentViewFrameOrigin = self.contentView.frame.origin
  505.         }
  506.        
  507.         if tmpCircleViewFrameOrigin == nil {
  508.         tmpCircleViewFrameOrigin = self.circleBG.frame.origin
  509.         }
  510.        
  511.         var newContentViewFrameY = self.contentView.frame.maxY - endKeyBoardFrame
  512.         if newContentViewFrameY < 0 {
  513.             newContentViewFrameY = 0
  514.         }
  515.         let newBallViewFrameY = self.circleBG.frame.origin.y - newContentViewFrameY
  516.         self.contentView.frame.origin.y -= newContentViewFrameY
  517.         self.circleBG.frame.origin.y = newBallViewFrameY
  518.     }
  519.    
  520.     func keyboardWillHide(_ notification: Notification) {
  521.         if(keyboardHasBeenShown){//This could happen on the simulator (keyboard will be hidden)
  522.             if(self.tmpContentViewFrameOrigin != nil){
  523.                 self.contentView.frame.origin.y = self.tmpContentViewFrameOrigin!.y
  524.                 self.tmpContentViewFrameOrigin = nil
  525.             }
  526.             if(self.tmpCircleViewFrameOrigin != nil){
  527.                 self.circleBG.frame.origin.y = self.tmpCircleViewFrameOrigin!.y
  528.                 self.tmpCircleViewFrameOrigin = nil
  529.             }
  530.            
  531.             keyboardHasBeenShown = false
  532.         }
  533.     }
  534.    
  535.     //Dismiss keyboard when tapped outside textfield & close SCLAlertView when hideWhenBackgroundViewIsTapped
  536.     func tapped(_ gestureRecognizer: UITapGestureRecognizer) {
  537.         self.view.endEditing(true)
  538.        
  539.         if let tappedView = gestureRecognizer.view , tappedView.hitTest(gestureRecognizer.location(in: tappedView), with: nil) == baseView && appearance.hideWhenBackgroundViewIsTapped {
  540.            
  541.             hideView()
  542.         }
  543.     }
  544.    
  545.     // showCustom(view, title, subTitle, UIColor, UIImage)
  546.     open func showCustom(_ title: String, subTitle: String, color: UIColor, icon: UIImage, closeButtonTitle:String?=nil, duration:TimeInterval=0.0, colorStyle: UInt=SCLAlertViewStyle.success.defaultColorInt, colorTextButton: UInt=0xFFFFFF, circleIconImage: UIImage? = nil, animationStyle: SCLAnimationStyle = .topToBottom) -> SCLAlertViewResponder {
  547.        
  548.        
  549.         var red: CGFloat = 0, green: CGFloat = 0, blue: CGFloat = 0, alpha: CGFloat = 0
  550.        
  551.         color.getRed(&red, green: &green, blue: &blue, alpha: &alpha)
  552.        
  553.         var colorAsUInt32 : UInt32 = 0
  554.         var redColor16 = UInt32(red * 255.0) << 16
  555.         colorAsUInt32 += redColor16 + UInt32(green * 255.0) << 8 + UInt32(blue * 255.0)
  556.        
  557.         let colorAsUInt = UInt(colorAsUInt32)
  558.        
  559.         return showTitle(title, subTitle: subTitle, duration: duration, completeText:closeButtonTitle, style: .success, colorStyle: colorAsUInt, colorTextButton: colorTextButton, circleIconImage: icon, animationStyle: animationStyle)
  560.     }
  561.    
  562.     // showSuccess(view, title, subTitle)
  563.     open func showSuccess(_ title: String, subTitle: String, closeButtonTitle:String?=nil, duration:TimeInterval=0.0, colorStyle: UInt=SCLAlertViewStyle.success.defaultColorInt, colorTextButton: UInt=0xFFFFFF, circleIconImage: UIImage? = nil, animationStyle: SCLAnimationStyle = .topToBottom) -> SCLAlertViewResponder {
  564.         return showTitle(title, subTitle: subTitle, duration: duration, completeText:closeButtonTitle, style: .success, colorStyle: colorStyle, colorTextButton: colorTextButton, circleIconImage: circleIconImage, animationStyle: animationStyle)
  565.     }
  566.    
  567.     // showError(view, title, subTitle)
  568.     open func showError(_ title: String, subTitle: String, closeButtonTitle:String?=nil, duration:TimeInterval=0.0, colorStyle: UInt=SCLAlertViewStyle.error.defaultColorInt, colorTextButton: UInt=0xFFFFFF, circleIconImage: UIImage? = nil, animationStyle: SCLAnimationStyle = .topToBottom) -> SCLAlertViewResponder {
  569.         return showTitle(title, subTitle: subTitle, duration: duration, completeText:closeButtonTitle, style: .error, colorStyle: colorStyle, colorTextButton: colorTextButton, circleIconImage: circleIconImage, animationStyle: animationStyle)
  570.     }
  571.    
  572.     // showNotice(view, title, subTitle)
  573.     open func showNotice(_ title: String, subTitle: String, closeButtonTitle:String?=nil, duration:TimeInterval=0.0, colorStyle: UInt=SCLAlertViewStyle.notice.defaultColorInt, colorTextButton: UInt=0xFFFFFF, circleIconImage: UIImage? = nil, animationStyle: SCLAnimationStyle = .topToBottom) -> SCLAlertViewResponder {
  574.         return showTitle(title, subTitle: subTitle, duration: duration, completeText:closeButtonTitle, style: .notice, colorStyle: colorStyle, colorTextButton: colorTextButton, circleIconImage: circleIconImage, animationStyle: animationStyle)
  575.     }
  576.    
  577.     // showWarning(view, title, subTitle)
  578.     open func showWarning(_ title: String, subTitle: String, closeButtonTitle:String?=nil, duration:TimeInterval=0.0, colorStyle: UInt=SCLAlertViewStyle.warning.defaultColorInt, colorTextButton: UInt=0x000000, circleIconImage: UIImage? = nil, animationStyle: SCLAnimationStyle = .topToBottom) -> SCLAlertViewResponder {
  579.         return showTitle(title, subTitle: subTitle, duration: duration, completeText:closeButtonTitle, style: .warning, colorStyle: colorStyle, colorTextButton: colorTextButton, circleIconImage: circleIconImage, animationStyle: animationStyle)
  580.     }
  581.    
  582.     // showInfo(view, title, subTitle)
  583.     open func showInfo(_ title: String, subTitle: String, closeButtonTitle:String?=nil, duration:TimeInterval=0.0, colorStyle: UInt=SCLAlertViewStyle.info.defaultColorInt, colorTextButton: UInt=0xFFFFFF, circleIconImage: UIImage? = nil, animationStyle: SCLAnimationStyle = .topToBottom) -> SCLAlertViewResponder {
  584.         return showTitle(title, subTitle: subTitle, duration: duration, completeText:closeButtonTitle, style: .info, colorStyle: colorStyle, colorTextButton: colorTextButton, circleIconImage: circleIconImage, animationStyle: animationStyle)
  585.     }
  586.    
  587.     // showWait(view, title, subTitle)
  588.     open func showWait(_ title: String, subTitle: String, closeButtonTitle:String?=nil, duration:TimeInterval=0.0, colorStyle: UInt?=SCLAlertViewStyle.wait.defaultColorInt, colorTextButton: UInt=0xFFFFFF, circleIconImage: UIImage? = nil, animationStyle: SCLAnimationStyle = .topToBottom) -> SCLAlertViewResponder {
  589.         return showTitle(title, subTitle: subTitle, duration: duration, completeText:closeButtonTitle, style: .wait, colorStyle: colorStyle, colorTextButton: colorTextButton, circleIconImage: circleIconImage, animationStyle: animationStyle)
  590.     }
  591.    
  592.     open func showEdit(_ title: String, subTitle: String, closeButtonTitle:String?=nil, duration:TimeInterval=0.0, colorStyle: UInt=SCLAlertViewStyle.edit.defaultColorInt, colorTextButton: UInt=0xFFFFFF, circleIconImage: UIImage? = nil, animationStyle: SCLAnimationStyle = .topToBottom) -> SCLAlertViewResponder {
  593.         return showTitle(title, subTitle: subTitle, duration: duration, completeText:closeButtonTitle, style: .edit, colorStyle: colorStyle, colorTextButton: colorTextButton, circleIconImage: circleIconImage, animationStyle: animationStyle)
  594.     }
  595.    
  596.     // showTitle(view, title, subTitle, style)
  597.     open func showTitle(_ title: String, subTitle: String, style: SCLAlertViewStyle, closeButtonTitle:String?=nil, duration:TimeInterval=0.0, colorStyle: UInt?=0x000000, colorTextButton: UInt=0xFFFFFF, circleIconImage: UIImage? = nil, animationStyle: SCLAnimationStyle = .topToBottom) -> SCLAlertViewResponder {
  598.        
  599.         return showTitle(title, subTitle: subTitle, duration:duration, completeText:closeButtonTitle, style: style, colorStyle: colorStyle, colorTextButton: colorTextButton, circleIconImage: circleIconImage, animationStyle: animationStyle)
  600.     }
  601.    
  602.     // showTitle(view, title, subTitle, duration, style)
  603.     open func showTitle(_ title: String, subTitle: String, duration: TimeInterval?, completeText: String?, style: SCLAlertViewStyle, colorStyle: UInt?=0x000000, colorTextButton: UInt?=0xFFFFFF, circleIconImage: UIImage? = nil, animationStyle: SCLAnimationStyle = .topToBottom) -> SCLAlertViewResponder {
  604.         selfReference = self
  605.         view.alpha = 0
  606.         let rv = UIApplication.shared.keyWindow! as UIWindow
  607.         rv.addSubview(view)
  608.         view.frame = rv.bounds
  609.         baseView.frame = rv.bounds
  610.        
  611.         // Alert colour/icon
  612.         viewColor = UIColor()
  613.         var iconImage: UIImage?
  614.         let colorInt = colorStyle ?? style.defaultColorInt
  615.         viewColor = UIColorFromRGB(colorInt)
  616.         // Icon style
  617.         switch style {
  618.         case .success:
  619.            
  620.             iconImage = checkCircleIconImage(circleIconImage, defaultImage: SCLAlertViewStyleKit.imageOfCheckmark)
  621.            
  622.         case .error:
  623.            
  624.             iconImage = checkCircleIconImage(circleIconImage, defaultImage: SCLAlertViewStyleKit.imageOfCross)
  625.            
  626.         case .notice:
  627.            
  628.             iconImage = checkCircleIconImage(circleIconImage, defaultImage:SCLAlertViewStyleKit.imageOfNotice)
  629.            
  630.         case .warning:
  631.            
  632.             iconImage = checkCircleIconImage(circleIconImage, defaultImage:SCLAlertViewStyleKit.imageOfWarning)
  633.            
  634.         case .info:
  635.            
  636.             iconImage = checkCircleIconImage(circleIconImage, defaultImage:SCLAlertViewStyleKit.imageOfInfo)
  637.            
  638.         case .edit:
  639.            
  640.             iconImage = checkCircleIconImage(circleIconImage, defaultImage:SCLAlertViewStyleKit.imageOfEdit)
  641.            
  642.         case .wait:
  643.             iconImage = nil
  644.         }
  645.        
  646.         // Title
  647.         if !title.isEmpty {
  648.             self.labelTitle.text = title
  649.         }
  650.        
  651.         // Subtitle
  652.         if !subTitle.isEmpty {
  653.             viewText.text = subTitle
  654.             // Adjust text view size, if necessary
  655.             let str = subTitle as NSString
  656.             let attr = [NSFontAttributeName:viewText.font ?? UIFont()]
  657.             let sz = CGSize(width: appearance.kWindowWidth - 24, height:90)
  658.             let r = str.boundingRect(with: sz, options: NSStringDrawingOptions.usesLineFragmentOrigin, attributes:attr, context:nil)
  659.             let ht = ceil(r.size.height)
  660.             if ht < appearance.kTextHeight {
  661.                 appearance.kWindowHeight -= (appearance.kTextHeight - ht)
  662.                 appearance.setkTextHeight(ht)
  663.             }
  664.         }
  665.        
  666.         // Done button
  667.         if appearance.showCloseButton {
  668.             addButton(completeText ?? "Done", target:self, selector:#selector(SCLAlertView.hideView))
  669.         }
  670.        
  671.         //hidden/show circular view based on the ui option
  672.         circleView.isHidden = !appearance.showCircularIcon
  673.         circleBG.isHidden = !appearance.showCircularIcon
  674.        
  675.         // Alert view colour and images
  676.         circleView.backgroundColor = viewColor
  677.         // Spinner / icon
  678.         if style == .wait {
  679.             let indicator = UIActivityIndicatorView(activityIndicatorStyle: .whiteLarge)
  680.             indicator.startAnimating()
  681.             circleIconView = indicator
  682.         }
  683.         else {
  684.             if let iconTintColor = iconTintColor {
  685.                 circleIconView = UIImageView(image: iconImage!.withRenderingMode(.alwaysTemplate))
  686.                 circleIconView?.tintColor = iconTintColor
  687.             }
  688.             else {
  689.                 circleIconView = UIImageView(image: iconImage!)
  690.             }
  691.         }
  692.         circleView.addSubview(circleIconView!)
  693.         let x = (appearance.kCircleHeight - appearance.kCircleIconHeight) / 2
  694.         circleIconView!.frame = CGRect( x: x, y: x, width: appearance.kCircleIconHeight, height: appearance.kCircleIconHeight)
  695.         circleIconView?.layer.cornerRadius = circleIconView!.bounds.height / 2
  696.         circleIconView?.layer.masksToBounds = true
  697.        
  698.         for txt in inputs {
  699.             txt.layer.borderColor = viewColor.cgColor
  700.         }
  701.        
  702.         for txt in input {
  703.             txt.layer.borderColor = viewColor.cgColor
  704.         }
  705.        
  706.         for btn in buttons {
  707.             if let customBackgroundColor = btn.customBackgroundColor {
  708.                 // Custom BackgroundColor set
  709.                 btn.backgroundColor = customBackgroundColor
  710.             } else {
  711.                 // Use default BackgroundColor derived from AlertStyle
  712.                 btn.backgroundColor = viewColor
  713.             }
  714.            
  715.             if let customTextColor = btn.customTextColor {
  716.                 // Custom TextColor set
  717.                 btn.setTitleColor(customTextColor, for:UIControlState())
  718.             } else {
  719.                 // Use default BackgroundColor derived from AlertStyle
  720.                 btn.setTitleColor(UIColorFromRGB(colorTextButton ?? 0xFFFFFF), for:UIControlState())
  721.             }
  722.         }
  723.        
  724.         // Adding duration
  725.         if duration > 0 {
  726.             self.duration = duration
  727.             durationTimer?.invalidate()
  728.             durationTimer = Timer.scheduledTimer(timeInterval: self.duration, target: self, selector: #selector(SCLAlertView.hideView), userInfo: nil, repeats: false)
  729.             durationStatusTimer?.invalidate()
  730.             durationStatusTimer = Timer.scheduledTimer(timeInterval: 1.0, target: self, selector: #selector(SCLAlertView.updateDurationStatus), userInfo: nil, repeats: true)
  731.         }
  732.        
  733.         // Animate in the alert view
  734.         self.showAnimation(animationStyle)
  735.        
  736.         // Chainable objects
  737.         return SCLAlertViewResponder(alertview: self)
  738.     }
  739.    
  740.     // Show animation in the alert view
  741.     fileprivate func showAnimation(_ animationStyle: SCLAnimationStyle = .topToBottom, animationStartOffset: CGFloat = -400.0, boundingAnimationOffset: CGFloat = 15.0, animationDuration: TimeInterval = 0.2) {
  742.        
  743.         let rv = UIApplication.shared.keyWindow! as UIWindow
  744.         var animationStartOrigin = self.baseView.frame.origin
  745.         var animationCenter : CGPoint = rv.center
  746.        
  747.         switch animationStyle {
  748.  
  749.         case .noAnimation:
  750.             self.view.alpha = 1.0
  751.             return;
  752.            
  753.         case .topToBottom:
  754.             animationStartOrigin = CGPoint(x: animationStartOrigin.x, y: self.baseView.frame.origin.y + animationStartOffset)
  755.             animationCenter = CGPoint(x: animationCenter.x, y: animationCenter.y + boundingAnimationOffset)
  756.            
  757.         case .bottomToTop:
  758.             animationStartOrigin = CGPoint(x: animationStartOrigin.x, y: self.baseView.frame.origin.y - animationStartOffset)
  759.             animationCenter = CGPoint(x: animationCenter.x, y: animationCenter.y - boundingAnimationOffset)
  760.            
  761.         case .leftToRight:
  762.             animationStartOrigin = CGPoint(x: self.baseView.frame.origin.x + animationStartOffset, y: animationStartOrigin.y)
  763.             animationCenter = CGPoint(x: animationCenter.x + boundingAnimationOffset, y: animationCenter.y)
  764.            
  765.         case .rightToLeft:
  766.             animationStartOrigin = CGPoint(x: self.baseView.frame.origin.x - animationStartOffset, y: animationStartOrigin.y)
  767.             animationCenter = CGPoint(x: animationCenter.x - boundingAnimationOffset, y: animationCenter.y)
  768.         }
  769.  
  770.         self.baseView.frame.origin = animationStartOrigin
  771.         UIView.animate(withDuration: animationDuration, animations: {
  772.             self.view.alpha = 1.0
  773.             self.baseView.center = animationCenter
  774.             }, completion: { finished in
  775.                 UIView.animate(withDuration: animationDuration, animations: {
  776.                     self.view.alpha = 1.0
  777.                     self.baseView.center = rv.center
  778.                 })
  779.         })
  780.     }
  781.    
  782.     open func updateDurationStatus() {
  783.         duration = duration.advanced(by: -1)
  784.         for btn in buttons.filter({$0.showDurationStatus}) {
  785.             let txt = "\(btn.initialTitle) (\(duration))"
  786.             btn.setTitle(txt, for: UIControlState())
  787.         }
  788.     }
  789.    
  790.     // Close SCLAlertView
  791.     open func hideView() {
  792.         UIView.animate(withDuration: 0.2, animations: {
  793.             self.view.alpha = 0
  794.             }, completion: { finished in
  795.                
  796.                 //Stop durationTimer so alertView does not attempt to hide itself and fire it's dimiss block a second time when close button is tapped
  797.                 self.durationTimer?.invalidate()
  798.                 // Stop StatusTimer
  799.                 self.durationStatusTimer?.invalidate()
  800.                
  801.                 if(self.dismissBlock != nil) {
  802.                     // Call completion handler when the alert is dismissed
  803.                     self.dismissBlock!()
  804.                 }
  805.                
  806.                 // This is necessary for SCLAlertView to be de-initialized, preventing a strong reference cycle with the viewcontroller calling SCLAlertView.
  807.                 for button in self.buttons {
  808.                     button.action = nil
  809.                     button.target = nil
  810.                     button.selector = nil
  811.                 }
  812.                
  813.                 self.view.removeFromSuperview()
  814.                 self.selfReference = nil
  815.         })
  816.     }
  817.    
  818.     func checkCircleIconImage(_ circleIconImage: UIImage?, defaultImage: UIImage) -> UIImage {
  819.         if let image = circleIconImage {
  820.             return image
  821.         } else {
  822.             return defaultImage
  823.         }
  824.     }
  825. }
  826.  
  827. // Helper function to convert from RGB to UIColor
  828. func UIColorFromRGB(_ rgbValue: UInt) -> UIColor {
  829.     return UIColor(
  830.         red: CGFloat((rgbValue & 0xFF0000) >> 16) / 255.0,
  831.         green: CGFloat((rgbValue & 0x00FF00) >> 8) / 255.0,
  832.         blue: CGFloat(rgbValue & 0x0000FF) / 255.0,
  833.         alpha: CGFloat(1.0)
  834.     )
  835. }
  836.  
  837. // ------------------------------------
  838. // Icon drawing
  839. // Code generated by PaintCode
  840. // ------------------------------------
  841.  
  842. class SCLAlertViewStyleKit : NSObject {
  843.    
  844.     // Cache
  845.     struct Cache {
  846.         static var imageOfCheckmark: UIImage?
  847.         static var checkmarkTargets: [AnyObject]?
  848.         static var imageOfCross: UIImage?
  849.         static var crossTargets: [AnyObject]?
  850.         static var imageOfNotice: UIImage?
  851.         static var noticeTargets: [AnyObject]?
  852.         static var imageOfWarning: UIImage?
  853.         static var warningTargets: [AnyObject]?
  854.         static var imageOfInfo: UIImage?
  855.         static var infoTargets: [AnyObject]?
  856.         static var imageOfEdit: UIImage?
  857.         static var editTargets: [AnyObject]?
  858.     }
  859.    
  860.     // Initialization
  861.     /// swift 1.2 abolish func load
  862.     //    override class func load() {
  863.     //    }
  864.    
  865.     // Drawing Methods
  866.     class func drawCheckmark() {
  867.         // Checkmark Shape Drawing
  868.         let checkmarkShapePath = UIBezierPath()
  869.         checkmarkShapePath.move(to: CGPoint(x: 73.25, y: 14.05))
  870.         checkmarkShapePath.addCurve(to: CGPoint(x: 64.51, y: 13.86), controlPoint1: CGPoint(x: 70.98, y: 11.44), controlPoint2: CGPoint(x: 66.78, y: 11.26))
  871.         checkmarkShapePath.addLine(to: CGPoint(x: 27.46, y: 52))
  872.         checkmarkShapePath.addLine(to: CGPoint(x: 15.75, y: 39.54))
  873.         checkmarkShapePath.addCurve(to: CGPoint(x: 6.84, y: 39.54), controlPoint1: CGPoint(x: 13.48, y: 36.93), controlPoint2: CGPoint(x: 9.28, y: 36.93))
  874.         checkmarkShapePath.addCurve(to: CGPoint(x: 6.84, y: 49.02), controlPoint1: CGPoint(x: 4.39, y: 42.14), controlPoint2: CGPoint(x: 4.39, y: 46.42))
  875.         checkmarkShapePath.addLine(to: CGPoint(x: 22.91, y: 66.14))
  876.         checkmarkShapePath.addCurve(to: CGPoint(x: 27.28, y: 68), controlPoint1: CGPoint(x: 24.14, y: 67.44), controlPoint2: CGPoint(x: 25.71, y: 68))
  877.         checkmarkShapePath.addCurve(to: CGPoint(x: 31.65, y: 66.14), controlPoint1: CGPoint(x: 28.86, y: 68), controlPoint2: CGPoint(x: 30.43, y: 67.26))
  878.         checkmarkShapePath.addLine(to: CGPoint(x: 73.08, y: 23.35))
  879.         checkmarkShapePath.addCurve(to: CGPoint(x: 73.25, y: 14.05), controlPoint1: CGPoint(x: 75.52, y: 20.75), controlPoint2: CGPoint(x: 75.7, y: 16.65))
  880.         checkmarkShapePath.close()
  881.         checkmarkShapePath.miterLimit = 4;
  882.        
  883.         UIColor.white.setFill()
  884.         checkmarkShapePath.fill()
  885.     }
  886.    
  887.     class func drawCross() {
  888.         // Cross Shape Drawing
  889.         let crossShapePath = UIBezierPath()
  890.         crossShapePath.move(to: CGPoint(x: 10, y: 70))
  891.         crossShapePath.addLine(to: CGPoint(x: 70, y: 10))
  892.         crossShapePath.move(to: CGPoint(x: 10, y: 10))
  893.         crossShapePath.addLine(to: CGPoint(x: 70, y: 70))
  894.         crossShapePath.lineCapStyle = CGLineCap.round;
  895.         crossShapePath.lineJoinStyle = CGLineJoin.round;
  896.         UIColor.white.setStroke()
  897.         crossShapePath.lineWidth = 14
  898.         crossShapePath.stroke()
  899.     }
  900.    
  901.     class func drawNotice() {
  902.         // Notice Shape Drawing
  903.         let noticeShapePath = UIBezierPath()
  904.         noticeShapePath.move(to: CGPoint(x: 72, y: 48.54))
  905.         noticeShapePath.addLine(to: CGPoint(x: 72, y: 39.9))
  906.         noticeShapePath.addCurve(to: CGPoint(x: 66.38, y: 34.01), controlPoint1: CGPoint(x: 72, y: 36.76), controlPoint2: CGPoint(x: 69.48, y: 34.01))
  907.         noticeShapePath.addCurve(to: CGPoint(x: 61.53, y: 35.97), controlPoint1: CGPoint(x: 64.82, y: 34.01), controlPoint2: CGPoint(x: 62.69, y: 34.8))
  908.         noticeShapePath.addCurve(to: CGPoint(x: 60.36, y: 35.78), controlPoint1: CGPoint(x: 61.33, y: 35.97), controlPoint2: CGPoint(x: 62.3, y: 35.78))
  909.         noticeShapePath.addLine(to: CGPoint(x: 60.36, y: 33.22))
  910.         noticeShapePath.addCurve(to: CGPoint(x: 54.16, y: 26.16), controlPoint1: CGPoint(x: 60.36, y: 29.3), controlPoint2: CGPoint(x: 57.65, y: 26.16))
  911.         noticeShapePath.addCurve(to: CGPoint(x: 48.73, y: 29.89), controlPoint1: CGPoint(x: 51.64, y: 26.16), controlPoint2: CGPoint(x: 50.67, y: 27.73))
  912.         noticeShapePath.addLine(to: CGPoint(x: 48.73, y: 28.71))
  913.         noticeShapePath.addCurve(to: CGPoint(x: 43.49, y: 21.64), controlPoint1: CGPoint(x: 48.73, y: 24.78), controlPoint2: CGPoint(x: 46.98, y: 21.64))
  914.         noticeShapePath.addCurve(to: CGPoint(x: 39.03, y: 25.37), controlPoint1: CGPoint(x: 40.97, y: 21.64), controlPoint2: CGPoint(x: 39.03, y: 23.01))
  915.         noticeShapePath.addLine(to: CGPoint(x: 39.03, y: 9.07))
  916.         noticeShapePath.addCurve(to: CGPoint(x: 32.24, y: 2), controlPoint1: CGPoint(x: 39.03, y: 5.14), controlPoint2: CGPoint(x: 35.73, y: 2))
  917.         noticeShapePath.addCurve(to: CGPoint(x: 25.45, y: 9.07), controlPoint1: CGPoint(x: 28.56, y: 2), controlPoint2: CGPoint(x: 25.45, y: 5.14))
  918.         noticeShapePath.addLine(to: CGPoint(x: 25.45, y: 41.47))
  919.         noticeShapePath.addCurve(to: CGPoint(x: 24.29, y: 43.44), controlPoint1: CGPoint(x: 25.45, y: 42.45), controlPoint2: CGPoint(x: 24.68, y: 43.04))
  920.         noticeShapePath.addCurve(to: CGPoint(x: 9.55, y: 43.04), controlPoint1: CGPoint(x: 16.73, y: 40.88), controlPoint2: CGPoint(x: 11.88, y: 40.69))
  921.         noticeShapePath.addCurve(to: CGPoint(x: 8, y: 46.58), controlPoint1: CGPoint(x: 8.58, y: 43.83), controlPoint2: CGPoint(x: 8, y: 45.2))
  922.         noticeShapePath.addCurve(to: CGPoint(x: 14.4, y: 55.81), controlPoint1: CGPoint(x: 8.19, y: 50.31), controlPoint2: CGPoint(x: 12.07, y: 53.84))
  923.         noticeShapePath.addLine(to: CGPoint(x: 27.2, y: 69.56))
  924.         noticeShapePath.addCurve(to: CGPoint(x: 42.91, y: 77.8), controlPoint1: CGPoint(x: 30.5, y: 74.47), controlPoint2: CGPoint(x: 35.73, y: 77.21))
  925.         noticeShapePath.addCurve(to: CGPoint(x: 43.88, y: 77.8), controlPoint1: CGPoint(x: 43.3, y: 77.8), controlPoint2: CGPoint(x: 43.68, y: 77.8))
  926.         noticeShapePath.addCurve(to: CGPoint(x: 47.18, y: 78), controlPoint1: CGPoint(x: 45.04, y: 77.8), controlPoint2: CGPoint(x: 46.01, y: 78))
  927.         noticeShapePath.addLine(to: CGPoint(x: 48.34, y: 78))
  928.         noticeShapePath.addLine(to: CGPoint(x: 48.34, y: 78))
  929.         noticeShapePath.addCurve(to: CGPoint(x: 71.61, y: 52.08), controlPoint1: CGPoint(x: 56.48, y: 78), controlPoint2: CGPoint(x: 69.87, y: 75.05))
  930.         noticeShapePath.addCurve(to: CGPoint(x: 72, y: 48.54), controlPoint1: CGPoint(x: 71.81, y: 51.29), controlPoint2: CGPoint(x: 72, y: 49.72))
  931.         noticeShapePath.close()
  932.         noticeShapePath.miterLimit = 4;
  933.        
  934.         UIColor.white.setFill()
  935.         noticeShapePath.fill()
  936.     }
  937.    
  938.     class func drawWarning() {
  939.         // Color Declarations
  940.         let greyColor = UIColor(red: 0.236, green: 0.236, blue: 0.236, alpha: 1.000)
  941.        
  942.         // Warning Group
  943.         // Warning Circle Drawing
  944.         let warningCirclePath = UIBezierPath()
  945.         warningCirclePath.move(to: CGPoint(x: 40.94, y: 63.39))
  946.         warningCirclePath.addCurve(to: CGPoint(x: 36.03, y: 65.55), controlPoint1: CGPoint(x: 39.06, y: 63.39), controlPoint2: CGPoint(x: 37.36, y: 64.18))
  947.         warningCirclePath.addCurve(to: CGPoint(x: 34.14, y: 70.45), controlPoint1: CGPoint(x: 34.9, y: 66.92), controlPoint2: CGPoint(x: 34.14, y: 68.49))
  948.         warningCirclePath.addCurve(to: CGPoint(x: 36.22, y: 75.54), controlPoint1: CGPoint(x: 34.14, y: 72.41), controlPoint2: CGPoint(x: 34.9, y: 74.17))
  949.         warningCirclePath.addCurve(to: CGPoint(x: 40.94, y: 77.5), controlPoint1: CGPoint(x: 37.54, y: 76.91), controlPoint2: CGPoint(x: 39.06, y: 77.5))
  950.         warningCirclePath.addCurve(to: CGPoint(x: 45.86, y: 75.35), controlPoint1: CGPoint(x: 42.83, y: 77.5), controlPoint2: CGPoint(x: 44.53, y: 76.72))
  951.         warningCirclePath.addCurve(to: CGPoint(x: 47.93, y: 70.45), controlPoint1: CGPoint(x: 47.18, y: 74.17), controlPoint2: CGPoint(x: 47.93, y: 72.41))
  952.         warningCirclePath.addCurve(to: CGPoint(x: 45.86, y: 65.35), controlPoint1: CGPoint(x: 47.93, y: 68.49), controlPoint2: CGPoint(x: 47.18, y: 66.72))
  953.         warningCirclePath.addCurve(to: CGPoint(x: 40.94, y: 63.39), controlPoint1: CGPoint(x: 44.53, y: 64.18), controlPoint2: CGPoint(x: 42.83, y: 63.39))
  954.         warningCirclePath.close()
  955.         warningCirclePath.miterLimit = 4;
  956.        
  957.         greyColor.setFill()
  958.         warningCirclePath.fill()
  959.        
  960.        
  961.         // Warning Shape Drawing
  962.         let warningShapePath = UIBezierPath()
  963.         warningShapePath.move(to: CGPoint(x: 46.23, y: 4.26))
  964.         warningShapePath.addCurve(to: CGPoint(x: 40.94, y: 2.5), controlPoint1: CGPoint(x: 44.91, y: 3.09), controlPoint2: CGPoint(x: 43.02, y: 2.5))
  965.         warningShapePath.addCurve(to: CGPoint(x: 34.71, y: 4.26), controlPoint1: CGPoint(x: 38.68, y: 2.5), controlPoint2: CGPoint(x: 36.03, y: 3.09))
  966.         warningShapePath.addCurve(to: CGPoint(x: 31.5, y: 8.77), controlPoint1: CGPoint(x: 33.01, y: 5.44), controlPoint2: CGPoint(x: 31.5, y: 7.01))
  967.         warningShapePath.addLine(to: CGPoint(x: 31.5, y: 19.36))
  968.         warningShapePath.addLine(to: CGPoint(x: 34.71, y: 54.44))
  969.         warningShapePath.addCurve(to: CGPoint(x: 40.38, y: 58.16), controlPoint1: CGPoint(x: 34.9, y: 56.2), controlPoint2: CGPoint(x: 36.41, y: 58.16))
  970.         warningShapePath.addCurve(to: CGPoint(x: 45.67, y: 54.44), controlPoint1: CGPoint(x: 44.34, y: 58.16), controlPoint2: CGPoint(x: 45.67, y: 56.01))
  971.         warningShapePath.addLine(to: CGPoint(x: 48.5, y: 19.36))
  972.         warningShapePath.addLine(to: CGPoint(x: 48.5, y: 8.77))
  973.         warningShapePath.addCurve(to: CGPoint(x: 46.23, y: 4.26), controlPoint1: CGPoint(x: 48.5, y: 7.01), controlPoint2: CGPoint(x: 47.74, y: 5.44))
  974.         warningShapePath.close()
  975.         warningShapePath.miterLimit = 4;
  976.        
  977.         greyColor.setFill()
  978.         warningShapePath.fill()
  979.     }
  980.    
  981.     class func drawInfo() {
  982.         // Color Declarations
  983.         let color0 = UIColor(red: 1.000, green: 1.000, blue: 1.000, alpha: 1.000)
  984.        
  985.         // Info Shape Drawing
  986.         let infoShapePath = UIBezierPath()
  987.         infoShapePath.move(to: CGPoint(x: 45.66, y: 15.96))
  988.         infoShapePath.addCurve(to: CGPoint(x: 45.66, y: 5.22), controlPoint1: CGPoint(x: 48.78, y: 12.99), controlPoint2: CGPoint(x: 48.78, y: 8.19))
  989.         infoShapePath.addCurve(to: CGPoint(x: 34.34, y: 5.22), controlPoint1: CGPoint(x: 42.53, y: 2.26), controlPoint2: CGPoint(x: 37.47, y: 2.26))
  990.         infoShapePath.addCurve(to: CGPoint(x: 34.34, y: 15.96), controlPoint1: CGPoint(x: 31.22, y: 8.19), controlPoint2: CGPoint(x: 31.22, y: 12.99))
  991.         infoShapePath.addCurve(to: CGPoint(x: 45.66, y: 15.96), controlPoint1: CGPoint(x: 37.47, y: 18.92), controlPoint2: CGPoint(x: 42.53, y: 18.92))
  992.         infoShapePath.close()
  993.         infoShapePath.move(to: CGPoint(x: 48, y: 69.41))
  994.         infoShapePath.addCurve(to: CGPoint(x: 40, y: 77), controlPoint1: CGPoint(x: 48, y: 73.58), controlPoint2: CGPoint(x: 44.4, y: 77))
  995.         infoShapePath.addLine(to: CGPoint(x: 40, y: 77))
  996.         infoShapePath.addCurve(to: CGPoint(x: 32, y: 69.41), controlPoint1: CGPoint(x: 35.6, y: 77), controlPoint2: CGPoint(x: 32, y: 73.58))
  997.         infoShapePath.addLine(to: CGPoint(x: 32, y: 35.26))
  998.         infoShapePath.addCurve(to: CGPoint(x: 40, y: 27.67), controlPoint1: CGPoint(x: 32, y: 31.08), controlPoint2: CGPoint(x: 35.6, y: 27.67))
  999.         infoShapePath.addLine(to: CGPoint(x: 40, y: 27.67))
  1000.         infoShapePath.addCurve(to: CGPoint(x: 48, y: 35.26), controlPoint1: CGPoint(x: 44.4, y: 27.67), controlPoint2: CGPoint(x: 48, y: 31.08))
  1001.         infoShapePath.addLine(to: CGPoint(x: 48, y: 69.41))
  1002.         infoShapePath.close()
  1003.         color0.setFill()
  1004.         infoShapePath.fill()
  1005.     }
  1006.    
  1007.     class func drawEdit() {
  1008.         // Color Declarations
  1009.         let color = UIColor(red:1.0, green:1.0, blue:1.0, alpha:1.0)
  1010.        
  1011.         // Edit shape Drawing
  1012.         let editPathPath = UIBezierPath()
  1013.         editPathPath.move(to: CGPoint(x: 71, y: 2.7))
  1014.         editPathPath.addCurve(to: CGPoint(x: 71.9, y: 15.2), controlPoint1: CGPoint(x: 74.7, y: 5.9), controlPoint2: CGPoint(x: 75.1, y: 11.6))
  1015.         editPathPath.addLine(to: CGPoint(x: 64.5, y: 23.7))
  1016.         editPathPath.addLine(to: CGPoint(x: 49.9, y: 11.1))
  1017.         editPathPath.addLine(to: CGPoint(x: 57.3, y: 2.6))
  1018.         editPathPath.addCurve(to: CGPoint(x: 69.7, y: 1.7), controlPoint1: CGPoint(x: 60.4, y: -1.1), controlPoint2: CGPoint(x: 66.1, y: -1.5))
  1019.         editPathPath.addLine(to: CGPoint(x: 71, y: 2.7))
  1020.         editPathPath.addLine(to: CGPoint(x: 71, y: 2.7))
  1021.         editPathPath.close()
  1022.         editPathPath.move(to: CGPoint(x: 47.8, y: 13.5))
  1023.         editPathPath.addLine(to: CGPoint(x: 13.4, y: 53.1))
  1024.         editPathPath.addLine(to: CGPoint(x: 15.7, y: 55.1))
  1025.         editPathPath.addLine(to: CGPoint(x: 50.1, y: 15.5))
  1026.         editPathPath.addLine(to: CGPoint(x: 47.8, y: 13.5))
  1027.         editPathPath.addLine(to: CGPoint(x: 47.8, y: 13.5))
  1028.         editPathPath.close()
  1029.         editPathPath.move(to: CGPoint(x: 17.7, y: 56.7))
  1030.         editPathPath.addLine(to: CGPoint(x: 23.8, y: 62.2))
  1031.         editPathPath.addLine(to: CGPoint(x: 58.2, y: 22.6))
  1032.         editPathPath.addLine(to: CGPoint(x: 52, y: 17.1))
  1033.         editPathPath.addLine(to: CGPoint(x: 17.7, y: 56.7))
  1034.         editPathPath.addLine(to: CGPoint(x: 17.7, y: 56.7))
  1035.         editPathPath.close()
  1036.         editPathPath.move(to: CGPoint(x: 25.8, y: 63.8))
  1037.         editPathPath.addLine(to: CGPoint(x: 60.1, y: 24.2))
  1038.         editPathPath.addLine(to: CGPoint(x: 62.3, y: 26.1))
  1039.         editPathPath.addLine(to: CGPoint(x: 28.1, y: 65.7))
  1040.         editPathPath.addLine(to: CGPoint(x: 25.8, y: 63.8))
  1041.         editPathPath.addLine(to: CGPoint(x: 25.8, y: 63.8))
  1042.         editPathPath.close()
  1043.         editPathPath.move(to: CGPoint(x: 25.9, y: 68.1))
  1044.         editPathPath.addLine(to: CGPoint(x: 4.2, y: 79.5))
  1045.         editPathPath.addLine(to: CGPoint(x: 11.3, y: 55.5))
  1046.         editPathPath.addLine(to: CGPoint(x: 25.9, y: 68.1))
  1047.         editPathPath.close()
  1048.         editPathPath.miterLimit = 4;
  1049.         editPathPath.usesEvenOddFillRule = true;
  1050.         color.setFill()
  1051.         editPathPath.fill()
  1052.     }
  1053.    
  1054.     // Generated Images
  1055.     class var imageOfCheckmark: UIImage {
  1056.         if (Cache.imageOfCheckmark != nil) {
  1057.             return Cache.imageOfCheckmark!
  1058.         }
  1059.         UIGraphicsBeginImageContextWithOptions(CGSize(width: 80, height: 80), false, 0)
  1060.         SCLAlertViewStyleKit.drawCheckmark()
  1061.         Cache.imageOfCheckmark = UIGraphicsGetImageFromCurrentImageContext()
  1062.         UIGraphicsEndImageContext()
  1063.         return Cache.imageOfCheckmark!
  1064.     }
  1065.    
  1066.     class var imageOfCross: UIImage {
  1067.         if (Cache.imageOfCross != nil) {
  1068.             return Cache.imageOfCross!
  1069.         }
  1070.         UIGraphicsBeginImageContextWithOptions(CGSize(width: 80, height: 80), false, 0)
  1071.         SCLAlertViewStyleKit.drawCross()
  1072.         Cache.imageOfCross = UIGraphicsGetImageFromCurrentImageContext()
  1073.         UIGraphicsEndImageContext()
  1074.         return Cache.imageOfCross!
  1075.     }
  1076.    
  1077.     class var imageOfNotice: UIImage {
  1078.         if (Cache.imageOfNotice != nil) {
  1079.             return Cache.imageOfNotice!
  1080.         }
  1081.         UIGraphicsBeginImageContextWithOptions(CGSize(width: 80, height: 80), false, 0)
  1082.         SCLAlertViewStyleKit.drawNotice()
  1083.         Cache.imageOfNotice = UIGraphicsGetImageFromCurrentImageContext()
  1084.         UIGraphicsEndImageContext()
  1085.         return Cache.imageOfNotice!
  1086.     }
  1087.    
  1088.     class var imageOfWarning: UIImage {
  1089.         if (Cache.imageOfWarning != nil) {
  1090.             return Cache.imageOfWarning!
  1091.         }
  1092.         UIGraphicsBeginImageContextWithOptions(CGSize(width: 80, height: 80), false, 0)
  1093.         SCLAlertViewStyleKit.drawWarning()
  1094.         Cache.imageOfWarning = UIGraphicsGetImageFromCurrentImageContext()
  1095.         UIGraphicsEndImageContext()
  1096.         return Cache.imageOfWarning!
  1097.     }
  1098.    
  1099.     class var imageOfInfo: UIImage {
  1100.         if (Cache.imageOfInfo != nil) {
  1101.             return Cache.imageOfInfo!
  1102.         }
  1103.         UIGraphicsBeginImageContextWithOptions(CGSize(width: 80, height: 80), false, 0)
  1104.         SCLAlertViewStyleKit.drawInfo()
  1105.         Cache.imageOfInfo = UIGraphicsGetImageFromCurrentImageContext()
  1106.         UIGraphicsEndImageContext()
  1107.         return Cache.imageOfInfo!
  1108.     }
  1109.    
  1110.     class var imageOfEdit: UIImage {
  1111.         if (Cache.imageOfEdit != nil) {
  1112.             return Cache.imageOfEdit!
  1113.         }
  1114.         UIGraphicsBeginImageContextWithOptions(CGSize(width: 80, height: 80), false, 0)
  1115.         SCLAlertViewStyleKit.drawEdit()
  1116.         Cache.imageOfEdit = UIGraphicsGetImageFromCurrentImageContext()
  1117.         UIGraphicsEndImageContext()
  1118.         return Cache.imageOfEdit!
  1119.     }
  1120. }
Add Comment
Please, Sign In to add comment