diff --git a/FCAlertView/FCAlertView/FCAlertView.swift b/FCAlertView/FCAlertView/FCAlertView.swift index d2ca5a8..52e65bb 100644 --- a/FCAlertView/FCAlertView/FCAlertView.swift +++ b/FCAlertView/FCAlertView/FCAlertView.swift @@ -14,7 +14,7 @@ public enum FCAlertType { case warning } -public class FCAlertView: UIView { +open class FCAlertView: UIView { var defaultHeight: CGFloat = 200 var defaultSpacing: CGFloat = 105 @@ -23,7 +23,7 @@ public class FCAlertView: UIView { var alertViewContents: UIView? let circleLayer: CAShapeLayer = { let circle = CAShapeLayer() - circle.fillColor = UIColor.whiteColor().CGColor + circle.fillColor = UIColor.white.cgColor return circle }() @@ -35,7 +35,7 @@ public class FCAlertView: UIView { var firstRun = true //Delegate - public var delegate: FCAlertViewDelegate? + open var delegate: FCAlertViewDelegate? //AlertView Title & Subtitle Text var title: String? @@ -51,24 +51,24 @@ public class FCAlertView: UIView { // AlertView Customizations var numberOfButtons = 0 - public var autoHideSeconds = 0 - public var cornerRadius: CGFloat = 18 + open var autoHideSeconds = 0 + open var cornerRadius: CGFloat = 18 - public var dismissOnOutsideTouch = false - public var hideAllButtons = false - public var hideDoneButton = false + open var dismissOnOutsideTouch = false + open var hideAllButtons = false + open var hideDoneButton = false // Color Schemes - public var colorScheme: UIColor? - public var titleColor: UIColor = .blackColor() - public var subTitleColor: UIColor = .blackColor() + open var colorScheme: UIColor? + open var titleColor: UIColor = UIColor.black + open var subTitleColor: UIColor = UIColor.black public override init(frame: CGRect) { super.init(frame: frame) firstRun = true - backgroundColor = .clearColor() + backgroundColor = UIColor.clear addSubview(alertBackground) @@ -78,9 +78,9 @@ public class FCAlertView: UIView { // Default Init public convenience init() { - let result = UIScreen.mainScreen().bounds.size + let result = UIScreen.main.bounds.size - let frame = CGRectMake(0, 0, result.width, result.height) + let frame = CGRect(x: 0, y: 0, width: result.width, height: result.height) self.init(frame: frame) @@ -88,9 +88,9 @@ public class FCAlertView: UIView { // Initialize with a default theme public convenience init(type: FCAlertType){ - let result = UIScreen.mainScreen().bounds.size + let result = UIScreen.main.bounds.size - let frame = CGRectMake(0, 0, result.width, result.height) + let frame = CGRect(x: 0, y: 0, width: result.width, height: result.height) self.init(frame: frame) switch type { @@ -108,7 +108,7 @@ public class FCAlertView: UIView { } // MARK: Customization Data Checkpoint - private func checkCustomizationValid(){ + fileprivate func checkCustomizationValid(){ if (title == nil || title!.isEmpty) && subTitle.isEmpty { subTitle = "You need to have a title or subtitle to use FCAlertView 😀" @@ -128,13 +128,13 @@ public class FCAlertView: UIView { } // MARK: Touch Events - override public func touchesEnded(touches: Set, withEvent event: UIEvent?) { + override open func touchesEnded(_ touches: Set, with event: UIEvent?) { if let touch = touches.first { - let touchPoint = touch.locationInView(alertBackground) - let touchPoint2 = touch.locationInView(alertViewContents) + let touchPoint = touch.location(in: alertBackground) + let touchPoint2 = touch.location(in: alertViewContents) - let isPointInsideBackview = alertBackground.pointInside(touchPoint, withEvent: nil) - let isPointInsideAlertView = alertViewContents!.pointInside(touchPoint2, withEvent: nil) + let isPointInsideBackview = alertBackground.point(inside: touchPoint, with: nil) + let isPointInsideAlertView = alertViewContents!.point(inside: touchPoint2, with: nil) if dismissOnOutsideTouch && isPointInsideBackview && !isPointInsideAlertView { dismissAlertView() @@ -143,121 +143,121 @@ public class FCAlertView: UIView { } // MARK: Drawing AlertView - private func setupAlertViewFrame() -> CGRect { - let result = UIScreen.mainScreen().bounds.size + fileprivate func setupAlertViewFrame() -> CGRect { + let result = UIScreen.main.bounds.size var alertViewFrame: CGRect - - alertBackground.frame = CGRectMake(0, 0, self.frame.width, self.frame.height) + + alertBackground.frame = CGRect(x: 0, y: 0, width: self.frame.width, height: self.frame.height) // Adjusting AlertView Frames if alertViewWithVector == 1 { - alertViewFrame = CGRectMake(self.frame.size.width/2 - ((result.width - defaultSpacing)/2), - self.frame.size.height/2 - (200.0/2), - result.width - defaultSpacing, - defaultHeight) + alertViewFrame = CGRect(x: self.frame.size.width/2 - ((result.width - defaultSpacing)/2), + y: self.frame.size.height/2 - (200.0/2), + width: result.width - defaultSpacing, + height: defaultHeight) }else{ - alertViewFrame = CGRectMake(self.frame.size.width/2 - ((result.width - defaultSpacing)/2), - self.frame.size.height/2 - (170.0/2), - result.width - defaultSpacing, - defaultHeight - 30) + alertViewFrame = CGRect(x: self.frame.size.width/2 - ((result.width - defaultSpacing)/2), + y: self.frame.size.height/2 - (170.0/2), + width: result.width - defaultSpacing, + height: defaultHeight - 30) } // Frames for when AlertView doesn't contain a title if title == nil { - alertViewFrame = CGRectMake(self.frame.size.width/2 - ((result.width - defaultSpacing)/2), - self.frame.size.height/2 - ((alertViewFrame.size.height - 50)/2), - result.width - defaultSpacing, - alertViewFrame.size.height - 10) + alertViewFrame = CGRect(x: self.frame.size.width/2 - ((result.width - defaultSpacing)/2), + y: self.frame.size.height/2 - ((alertViewFrame.size.height - 50)/2), + width: result.width - defaultSpacing, + height: alertViewFrame.size.height - 10) } // Frames for when AlertView has hidden all buttons if hideAllButtons { - alertViewFrame = CGRectMake(self.frame.size.width/2 - ((result.width - defaultSpacing)/2), - self.frame.size.height/2 - ((alertViewFrame.size.height - 50)/2), result.width - defaultSpacing, - alertViewFrame.size.height - 45) + alertViewFrame = CGRect(x: self.frame.size.width/2 - ((result.width - defaultSpacing)/2), + y: self.frame.size.height/2 - ((alertViewFrame.size.height - 50)/2), width: result.width - defaultSpacing, + height: alertViewFrame.size.height - 45) } else{ // Frames for when AlertView has hidden the DONE/DISMISS button if hideDoneButton && numberOfButtons == 0 { - alertViewFrame = CGRectMake(self.frame.size.width/2 - ((result.width - defaultSpacing)/2), - self.frame.size.height/2 - ((alertViewFrame.size.height - 50)/2), result.width - defaultSpacing, - alertViewFrame.size.height - 45) + alertViewFrame = CGRect(x: self.frame.size.width/2 - ((result.width - defaultSpacing)/2), + y: self.frame.size.height/2 - ((alertViewFrame.size.height - 50)/2), width: result.width - defaultSpacing, + height: alertViewFrame.size.height - 45) } // Frames for AlertView with 2 added buttons (vertical buttons) if !hideDoneButton && numberOfButtons >= 2 { - alertViewFrame = CGRectMake(self.frame.size.width/2 - ((result.width - defaultSpacing)/2), - self.frame.size.height/2 - ((alertViewFrame.size.height - 50 + 140)/2), result.width - defaultSpacing, - alertViewFrame.size.height - 50 + 140) + alertViewFrame = CGRect(x: self.frame.size.width/2 - ((result.width - defaultSpacing)/2), + y: self.frame.size.height/2 - ((alertViewFrame.size.height - 50 + 140)/2), width: result.width - defaultSpacing, + height: alertViewFrame.size.height - 50 + 140) } } return alertViewFrame } - private func renderCircleCutout(withAlertViewFrame alertViewFrame: CGRect){ + fileprivate func renderCircleCutout(withAlertViewFrame alertViewFrame: CGRect){ let radius = alertView!.frame.size.width - let rectPath = UIBezierPath(roundedRect: CGRectMake(0, - 0, - frame.size.width, - alertView!.frame.size.height), + let rectPath = UIBezierPath(roundedRect: CGRect(x: 0, + y: 0, + width: frame.size.width, + height: alertView!.frame.size.height), cornerRadius: 0) - let circlePath = UIBezierPath(roundedRect: CGRectMake(alertViewFrame.size.width/2 - 33.75, - -33.75, - 67.5, - 67.5), + let circlePath = UIBezierPath(roundedRect: CGRect(x: alertViewFrame.size.width/2 - 33.75, + y: -33.75, + width: 67.5, + height: 67.5), cornerRadius: radius) - rectPath.appendPath(circlePath) + rectPath.append(circlePath) rectPath.usesEvenOddFillRule = true let fillLayer = CAShapeLayer() - fillLayer.path = rectPath.CGPath + fillLayer.path = rectPath.cgPath fillLayer.fillRule = kCAFillRuleEvenOdd - fillLayer.fillColor = UIColor.whiteColor().CGColor + fillLayer.fillColor = UIColor.white.cgColor fillLayer.opacity = 1 alertView!.layer.addSublayer(fillLayer) } - private func renderHeader(withAlertViewFrame alertViewFrame: CGRect){ - - let titleLabel = UILabel(frame: CGRectMake(15.0, - 20.0 + CGFloat(alertViewWithVector * 30), - alertViewFrame.size.width - 30.0, - 20.0)) - titleLabel.font = UIFont.systemFontOfSize(18, weight: UIFontWeightMedium) + fileprivate func renderHeader(withAlertViewFrame alertViewFrame: CGRect){ + + let titleLabel = UILabel(frame: CGRect(x: 15.0, + y: 20.0 + CGFloat(alertViewWithVector * 30), + width: alertViewFrame.size.width - 30.0, + height: 20.0)) + titleLabel.font = UIFont.systemFont(ofSize: 18, weight: UIFontWeightMedium) titleLabel.numberOfLines = 1 titleLabel.textColor = titleColor titleLabel.text = title - titleLabel.textAlignment = .Center + titleLabel.textAlignment = .center let descriptionLevel = (title == nil) ? 25 : 45 - let descriptionLabel = UILabel(frame: CGRectMake(25.0, - CGFloat(descriptionLevel + alertViewWithVector * 30), - alertViewFrame.size.width - 50.0, - 60.0)) - descriptionLabel.font = (title == nil) ? UIFont.systemFontOfSize(16, weight: UIFontWeightRegular) : - UIFont.systemFontOfSize(15, weight: UIFontWeightLight) + let descriptionLabel = UILabel(frame: CGRect(x: 25.0, + y: CGFloat(descriptionLevel + alertViewWithVector * 30), + width: alertViewFrame.size.width - 50.0, + height: 60.0)) + descriptionLabel.font = (title == nil) ? UIFont.systemFont(ofSize: 16, weight: UIFontWeightRegular) : + UIFont.systemFont(ofSize: 15, weight: UIFontWeightLight) descriptionLabel.numberOfLines = 4 descriptionLabel.textColor = subTitleColor descriptionLabel.text = subTitle - descriptionLabel.textAlignment = .Center + descriptionLabel.textAlignment = .center descriptionLabel.adjustsFontSizeToFitWidth = true // Separator Line - Separating Header View with Button View - let separatorLineView = UIView(frame: CGRectMake(0, - alertViewFrame.size.height - 47, - alertViewFrame.size.width, - 2)) + let separatorLineView = UIView(frame: CGRect(x: 0, + y: alertViewFrame.size.height - 47, + width: alertViewFrame.size.width, + height: 2)) separatorLineView.backgroundColor = UIColor(white: 100/255, alpha: 1) - let blurEffect = UIBlurEffect(style: .ExtraLight) + let blurEffect = UIBlurEffect(style: .extraLight) let visualEffectView = UIVisualEffectView(effect: blurEffect) visualEffectView.frame = separatorLineView.bounds - visualEffectView.userInteractionEnabled = false + visualEffectView.isUserInteractionEnabled = false separatorLineView.addSubview(visualEffectView) @@ -265,13 +265,13 @@ public class FCAlertView: UIView { alertViewContents!.addSubview(titleLabel) alertViewContents!.addSubview(descriptionLabel) -// numberOfButtons == 1 && !hideDoneButton && + // numberOfButtons == 1 && !hideDoneButton && if !hideAllButtons { alertViewContents!.addSubview(separatorLineView) } } - override public func drawRect(rect: CGRect) { + override open func draw(_ rect: CGRect) { alpha = 0 @@ -279,16 +279,16 @@ public class FCAlertView: UIView { // Setting up contents of AlertView alertViewContents = UIView(frame: alertViewFrame) - alertViewContents!.backgroundColor = .clearColor() + alertViewContents!.backgroundColor = UIColor.clear addSubview(alertViewContents!) - alertView = UIView(frame: CGRectMake(0, 0, alertViewFrame.size.width, alertViewFrame.size.height)) + alertView = UIView(frame: CGRect(x: 0, y: 0, width: alertViewFrame.size.width, height: alertViewFrame.size.height)) // Setting Background Color of AlertView if alertViewWithVector == 1 { - alertView!.backgroundColor = .clearColor() + alertView!.backgroundColor = UIColor.clear }else{ - alertView!.backgroundColor = .whiteColor() + alertView!.backgroundColor = UIColor.white } alertViewContents!.addSubview(alertView!) @@ -307,21 +307,21 @@ public class FCAlertView: UIView { // View only contains DONE/DISMISS Button if(!hideAllButtons && !hideDoneButton && numberOfButtons == 0) { - let doneButton = UIButton(type: .System) + let doneButton = UIButton(type: .system) if let colorScheme = self.colorScheme { doneButton.backgroundColor = colorScheme - doneButton.tintColor = .whiteColor() + doneButton.tintColor = UIColor.white }else{ - doneButton.backgroundColor = .whiteColor() + doneButton.backgroundColor = UIColor.white } - doneButton.frame = CGRectMake(0, - alertViewFrame.size.height - 45, - alertViewFrame.size.width, - 45) - doneButton.setTitle(doneTitle, forState: .Normal) - doneButton.addTarget(self, action: #selector(donePressed(_:)), forControlEvents: .TouchUpInside) - doneButton.titleLabel!.font = UIFont.systemFontOfSize(18, weight: UIFontWeightMedium) + doneButton.frame = CGRect(x: 0, + y: alertViewFrame.size.height - 45, + width: alertViewFrame.size.width, + height: 45) + doneButton.setTitle(doneTitle, for: UIControlState()) + doneButton.addTarget(self, action: #selector(donePressed(_:)), for: .touchUpInside) + doneButton.titleLabel!.font = UIFont.systemFont(ofSize: 18, weight: UIFontWeightMedium) alertView!.addSubview(doneButton) @@ -329,158 +329,158 @@ public class FCAlertView: UIView { else if !hideAllButtons && numberOfButtons == 1 { // View also contains OTHER (One) Button // Render user button - let otherButton = UIButton(type: .System) - otherButton.backgroundColor = .whiteColor() + let otherButton = UIButton(type: .system) + otherButton.backgroundColor = UIColor.white - otherButton.setTitle(buttonTitles![0], forState: .Normal) - otherButton.addTarget(self, action: #selector(handleButton(_:)), forControlEvents: .TouchUpInside) - otherButton.titleLabel?.font = UIFont.systemFontOfSize(16, weight: UIFontWeightRegular) + otherButton.setTitle(buttonTitles![0], for: UIControlState()) + otherButton.addTarget(self, action: #selector(handleButton(_:)), for: .touchUpInside) + otherButton.titleLabel?.font = UIFont.systemFont(ofSize: 16, weight: UIFontWeightRegular) otherButton.tintColor = colorScheme otherButton.titleLabel?.adjustsFontSizeToFitWidth = true otherButton.titleLabel?.minimumScaleFactor = 0.8 - + if !hideDoneButton { - otherButton.frame = CGRectMake(0, - alertViewFrame.size.height - 45, - alertViewFrame.size.width/2, - 45) + otherButton.frame = CGRect(x: 0, + y: alertViewFrame.size.height - 45, + width: alertViewFrame.size.width/2, + height: 45) //Render Done buttons - let doneButton = UIButton(type: .System) + let doneButton = UIButton(type: .system) if let colorScheme = self.colorScheme { doneButton.backgroundColor = colorScheme - doneButton.tintColor = .whiteColor() + doneButton.tintColor = UIColor.white }else{ - doneButton.backgroundColor = .whiteColor() + doneButton.backgroundColor = UIColor.white } - doneButton.frame = CGRectMake(alertViewFrame.size.width/2, - alertViewFrame.size.height - 45, - alertViewFrame.size.width/2, - 45) - doneButton.setTitle(doneTitle, forState: .Normal) - doneButton.addTarget(self, action: #selector(donePressed(_:)), forControlEvents: .TouchUpInside) - doneButton.titleLabel?.font = UIFont.systemFontOfSize(16, weight: UIFontWeightMedium) + doneButton.frame = CGRect(x: alertViewFrame.size.width/2, + y: alertViewFrame.size.height - 45, + width: alertViewFrame.size.width/2, + height: 45) + doneButton.setTitle(doneTitle, for: UIControlState()) + doneButton.addTarget(self, action: #selector(donePressed(_:)), for: .touchUpInside) + doneButton.titleLabel?.font = UIFont.systemFont(ofSize: 16, weight: UIFontWeightMedium) - let horizontalSeparator = UIView(frame: CGRectMake(alertViewFrame.size.width/2 - 1, - otherButton.frame.origin.y - 2, - 2, - 45)) + let horizontalSeparator = UIView(frame: CGRect(x: alertViewFrame.size.width/2 - 1, + y: otherButton.frame.origin.y - 2, + width: 2, + height: 45)) horizontalSeparator.backgroundColor = UIColor(white: 100/255, alpha: 1) - let blurEffect = UIBlurEffect(style: .ExtraLight) + let blurEffect = UIBlurEffect(style: .extraLight) let visualEffectView = UIVisualEffectView(effect: blurEffect) visualEffectView.frame = horizontalSeparator.bounds - visualEffectView.userInteractionEnabled = false + visualEffectView.isUserInteractionEnabled = false horizontalSeparator.addSubview(visualEffectView) alertView!.addSubview(doneButton) alertView!.addSubview(horizontalSeparator) }else{ - otherButton.frame = CGRectMake(0, - alertViewFrame.size.height - 45, - alertViewFrame.size.width, - 45) + otherButton.frame = CGRect(x: 0, + y: alertViewFrame.size.height - 45, + width: alertViewFrame.size.width, + height: 45) } alertView!.addSubview(otherButton) }else if(!hideAllButtons && numberOfButtons >= 2){ - let firstButton = UIButton(type: .System) - firstButton.backgroundColor = .whiteColor() + let firstButton = UIButton(type: .system) + firstButton.backgroundColor = UIColor.white if hideDoneButton { - firstButton.frame = CGRectMake(0, - alertViewFrame.size.height - 45, - alertViewFrame.size.width/2, - 45) + firstButton.frame = CGRect(x: 0, + y: alertViewFrame.size.height - 45, + width: alertViewFrame.size.width/2, + height: 45) }else { - firstButton.frame = CGRectMake(0, - alertViewFrame.size.height - 135, - alertViewFrame.size.width, - 45) + firstButton.frame = CGRect(x: 0, + y: alertViewFrame.size.height - 135, + width: alertViewFrame.size.width, + height: 45) } - firstButton.setTitle(buttonTitles![0], forState: .Normal) - firstButton.addTarget(self, action: #selector(handleButton(_:)), forControlEvents: .TouchUpInside) - firstButton.titleLabel?.font = UIFont.systemFontOfSize(16, weight: UIFontWeightRegular) + firstButton.setTitle(buttonTitles![0], for: UIControlState()) + firstButton.addTarget(self, action: #selector(handleButton(_:)), for: .touchUpInside) + firstButton.titleLabel?.font = UIFont.systemFont(ofSize: 16, weight: UIFontWeightRegular) firstButton.tintColor = colorScheme firstButton.titleLabel?.adjustsFontSizeToFitWidth = true firstButton.titleLabel?.minimumScaleFactor = 0.8 firstButton.tag = 0 - let secondButton = UIButton(type: .System) - secondButton.backgroundColor = .whiteColor() - secondButton.setTitle(buttonTitles![1], forState: .Normal) - secondButton.addTarget(self, action: #selector(handleButton(_:)), forControlEvents: .TouchUpInside) - secondButton.titleLabel?.font = UIFont.systemFontOfSize(16, weight: UIFontWeightRegular) + let secondButton = UIButton(type: .system) + secondButton.backgroundColor = UIColor.white + secondButton.setTitle(buttonTitles![1], for: UIControlState()) + secondButton.addTarget(self, action: #selector(handleButton(_:)), for: .touchUpInside) + secondButton.titleLabel?.font = UIFont.systemFont(ofSize: 16, weight: UIFontWeightRegular) secondButton.tintColor = colorScheme secondButton.titleLabel?.adjustsFontSizeToFitWidth = true secondButton.titleLabel?.minimumScaleFactor = 0.8 secondButton.tag = 0 - let firstSeparator = UIView(frame: CGRectMake(0, - firstButton.frame.origin.y - 2, - alertViewFrame.size.width, - 2)) + let firstSeparator = UIView(frame: CGRect(x: 0, + y: firstButton.frame.origin.y - 2, + width: alertViewFrame.size.width, + height: 2)) firstSeparator.backgroundColor = UIColor(white: 100/255, alpha: 1) - let secondSeparator = UIView(frame: CGRectMake(0, 0, 0, 0)) + let secondSeparator = UIView(frame: CGRect(x: 0, y: 0, width: 0, height: 0)) secondSeparator.backgroundColor = UIColor(white: 100/255, alpha: 1) - let blurEffect = UIBlurEffect(style: .ExtraLight) + let blurEffect = UIBlurEffect(style: .extraLight) let visualEffectView = UIVisualEffectView(effect: blurEffect) visualEffectView.frame = firstSeparator.bounds - visualEffectView.userInteractionEnabled = false + visualEffectView.isUserInteractionEnabled = false firstSeparator.addSubview(visualEffectView) let visualEffectView2 = UIVisualEffectView(effect: blurEffect) - visualEffectView2.userInteractionEnabled = false + visualEffectView2.isUserInteractionEnabled = false secondSeparator.addSubview(visualEffectView2) if !hideDoneButton { - secondButton.frame = CGRectMake(0, - alertViewFrame.size.height - 90, - alertViewFrame.size.width, - 45) - secondSeparator.frame = CGRectMake(0, - secondButton.frame.origin.y - 2, - alertViewFrame.size.width, - 2) - let doneButton = UIButton(type: .System) + secondButton.frame = CGRect(x: 0, + y: alertViewFrame.size.height - 90, + width: alertViewFrame.size.width, + height: 45) + secondSeparator.frame = CGRect(x: 0, + y: secondButton.frame.origin.y - 2, + width: alertViewFrame.size.width, + height: 2) + let doneButton = UIButton(type: .system) if let colorScheme = colorScheme { doneButton.backgroundColor = colorScheme - doneButton.tintColor = .whiteColor() + doneButton.tintColor = UIColor.white }else{ - doneButton.backgroundColor = .whiteColor() + doneButton.backgroundColor = UIColor.white } - doneButton.frame = CGRectMake(0, - alertViewFrame.size.height - 45, - alertViewFrame.size.width, - 45) - doneButton.setTitle(doneTitle, forState: .Normal) - doneButton.addTarget(self, action: #selector(donePressed(_:)), forControlEvents: .TouchUpInside) - doneButton.titleLabel?.font = UIFont.systemFontOfSize(18, weight: UIFontWeightMedium) + doneButton.frame = CGRect(x: 0, + y: alertViewFrame.size.height - 45, + width: alertViewFrame.size.width, + height: 45) + doneButton.setTitle(doneTitle, for: UIControlState()) + doneButton.addTarget(self, action: #selector(donePressed(_:)), for: .touchUpInside) + doneButton.titleLabel?.font = UIFont.systemFont(ofSize: 18, weight: UIFontWeightMedium) alertView!.addSubview(doneButton) }else { // Set proper frames for no donebutton - secondButton.frame = CGRectMake(alertViewFrame.size.width/2, - alertViewFrame.size.height - 45, - alertViewFrame.size.width/2, - 45) + secondButton.frame = CGRect(x: alertViewFrame.size.width/2, + y: alertViewFrame.size.height - 45, + width: alertViewFrame.size.width/2, + height: 45) - secondSeparator.frame = CGRectMake(alertViewFrame.size.width/2 - 1, - secondButton.frame.origin.y, - 2, - 45) + secondSeparator.frame = CGRect(x: alertViewFrame.size.width/2 - 1, + y: secondButton.frame.origin.y, + width: 2, + height: 45) } visualEffectView2.frame = secondSeparator.bounds @@ -491,18 +491,18 @@ public class FCAlertView: UIView { alertView!.addSubview(firstSeparator) alertView!.addSubview(secondSeparator) } - - circleLayer.path = UIBezierPath(ovalInRect: CGRectMake(alertViewContents!.frame.size.width/2 - 30.0, -30.0, 60.0, 60.0)).CGPath + + circleLayer.path = UIBezierPath(ovalIn: CGRect(x: alertViewContents!.frame.size.width/2 - 30.0, y: -30.0, width: 60.0, height: 60.0)).cgPath - let alertViewVector = UIButton(type: .System) - alertViewVector.frame = CGRectMake(alertViewContents!.frame.size.width/2 - 15.0, - -15.0, - 30.0, - 30.0) - alertViewVector.setImage(vectorImage, forState: .Normal) - alertViewVector.userInteractionEnabled = false + let alertViewVector = UIButton(type: .system) + alertViewVector.frame = CGRect(x: alertViewContents!.frame.size.width/2 - 15.0, + y: -15.0, + width: 30.0, + height: 30.0) + alertViewVector.setImage(vectorImage, for: UIControlState()) + alertViewVector.isUserInteractionEnabled = false alertViewVector.tintColor = colorScheme // VIEW Border - Rounding Corners of AlertView @@ -515,13 +515,13 @@ public class FCAlertView: UIView { } // Scaling AlertView - Before Animation - alertViewContents!.transform = CGAffineTransformMakeScale(1.15, 1.15) + alertViewContents!.transform = CGAffineTransform(scaleX: 1.15, y: 1.15) // Applying Shadow - layer.shadowColor = UIColor.blackColor().CGColor + layer.shadowColor = UIColor.black.cgColor layer.shadowOpacity = 0.1 layer.shadowRadius = 10 - layer.shadowOffset = CGSizeMake(0, 0) + layer.shadowOffset = CGSize(width: 0, height: 0) showAlertView() @@ -529,32 +529,32 @@ public class FCAlertView: UIView { // Default Types of Alerts - private func makeAlertTypeWarning() { - if let path = NSBundle(forClass: FCAlertView.self).pathForResource("close-round", ofType: "png") { + fileprivate func makeAlertTypeWarning() { + if let path = Bundle(for: FCAlertView.self).path(forResource: "close-round", ofType: "png") { setTheme(iconPath: path, tintColor: .flatRed) } } - private func makeAlertTypeCaution() { - if let path = NSBundle(forClass: FCAlertView.self).pathForResource("alert-round", ofType: "png") { + fileprivate func makeAlertTypeCaution() { + if let path = Bundle(for: FCAlertView.self).path(forResource: "alert-round", ofType: "png") { setTheme(iconPath: path, tintColor: .flatOrange) } } - private func makeAlertTypeSuccess(){ - if let path = NSBundle(forClass: FCAlertView.self).pathForResource("checkmark-round", ofType: "png") { + fileprivate func makeAlertTypeSuccess(){ + if let path = Bundle(for: FCAlertView.self).path(forResource: "checkmark-round", ofType: "png") { setTheme(iconPath: path, tintColor: .flatGreen) } } - private func setTheme(iconPath path: String, tintColor color: UIColor){ + fileprivate func setTheme(iconPath path: String, tintColor color: UIColor){ vectorImage = UIImage(contentsOfFile: path) alertViewWithVector = 1 self.colorScheme = color } //Presenting AlertView - public func showAlert(inView view: UIViewController, withTitle title: String?, withSubtitle subTitle: String, withCustomImage image: UIImage?, withDoneButtonTitle done: String?, andButtons buttons: [String]?) { + open func showAlert(inView view: UIViewController, withTitle title: String?, withSubtitle subTitle: String, withCustomImage image: UIImage?, withDoneButtonTitle done: String?, andButtons buttons: [String]?) { self.title = title self.subTitle = subTitle @@ -588,21 +588,21 @@ public class FCAlertView: UIView { delegate.FCAlertViewWillAppear(self) } - UIView.animateWithDuration(0.3, delay: 0.3, usingSpringWithDamping: 1, initialSpringVelocity: 1, options: .CurveEaseInOut, animations: { + UIView.animate(withDuration: 0.3, delay: 0.3, usingSpringWithDamping: 1, initialSpringVelocity: 1, options: UIViewAnimationOptions(), animations: { self.alpha = 1 - self.alertViewContents?.transform = CGAffineTransformMakeScale(1, 1) + self.alertViewContents?.transform = CGAffineTransform(scaleX: 1, y: 1) }) { (finished) in if self.autoHideSeconds != 0 { - self.performSelector(#selector(self.dismissAlertView), withObject: nil, afterDelay: Double(self.autoHideSeconds)) + self.perform(#selector(self.dismissAlertView), with: nil, afterDelay: Double(self.autoHideSeconds)) } } } // Dismissing AlertView - public func dismissAlertView() { - UIView.animateWithDuration(0.175, delay: 0, usingSpringWithDamping: 1, initialSpringVelocity: 1, options: .CurveEaseInOut, animations: { + open func dismissAlertView() { + UIView.animate(withDuration: 0.175, delay: 0, usingSpringWithDamping: 1, initialSpringVelocity: 1, options: UIViewAnimationOptions(), animations: { self.alpha = 0 - self.alertViewContents?.transform = CGAffineTransformMakeScale(0.9, 0.9) + self.alertViewContents?.transform = CGAffineTransform(scaleX: 0.9, y: 0.9) }) { (finished) in if let delegate = self.delegate { @@ -613,7 +613,7 @@ public class FCAlertView: UIView { } } - @objc private func handleButton(sender: UIButton){ + @objc fileprivate func handleButton(_ sender: UIButton){ guard let delegate = delegate else { return } @@ -623,7 +623,7 @@ public class FCAlertView: UIView { self.dismissAlertView() } - @objc private func donePressed(sender: UIButton){ + @objc fileprivate func donePressed(_ sender: UIButton){ if let delegate = delegate { delegate.FCAlertDoneButtonClicked(self) diff --git a/FCAlertView/FCAlertView/FCAlertViewDelegate.swift b/FCAlertView/FCAlertView/FCAlertViewDelegate.swift index 6d35079..5205240 100644 --- a/FCAlertView/FCAlertView/FCAlertViewDelegate.swift +++ b/FCAlertView/FCAlertView/FCAlertViewDelegate.swift @@ -9,18 +9,18 @@ import Foundation public protocol FCAlertViewDelegate: NSObjectProtocol { - func alertView(alertView: FCAlertView, clickedButtonIndex index: Int, buttonTitle title:String) + func alertView(_ alertView: FCAlertView, clickedButtonIndex index: Int, buttonTitle title:String) // Optional - func FCAlertViewDismissed(alertView: FCAlertView) - func FCAlertViewWillAppear(alertView: FCAlertView) - func FCAlertDoneButtonClicked(alertView: FCAlertView) + func FCAlertViewDismissed(_ alertView: FCAlertView) + func FCAlertViewWillAppear(_ alertView: FCAlertView) + func FCAlertDoneButtonClicked(_ alertView: FCAlertView) } // Provide default impementation for optional methods public extension FCAlertViewDelegate { - func FCAlertViewDismissed(alertView: FCAlertView) {} - func FCAlertViewWillAppear(alertView: FCAlertView) {} - func FCAlertDoneButtonClicked(alertView: FCAlertView) {} -} \ No newline at end of file + func FCAlertViewDismissed(_ alertView: FCAlertView) {} + func FCAlertViewWillAppear(_ alertView: FCAlertView) {} + func FCAlertDoneButtonClicked(_ alertView: FCAlertView) {} +}