diff --git a/Example/SCLAlertViewExample/ViewController.swift b/Example/SCLAlertViewExample/ViewController.swift index 045a9d4..1c0bc18 100644 --- a/Example/SCLAlertViewExample/ViewController.swift +++ b/Example/SCLAlertViewExample/ViewController.swift @@ -34,7 +34,7 @@ class ViewController: UIViewController { @IBAction func showSuccess(sender: AnyObject) { let alert = SCLAlertView() - alert.addButton("First Button", target:self, selector:Selector("firstButton")) + alert.addButton("First Button", target:self, selector:#selector(ViewController.firstButton)) alert.addButton("Second Button") { print("Second button tapped") } diff --git a/SCLAlertView.xcodeproj/project.pbxproj b/SCLAlertView.xcodeproj/project.pbxproj index 3964e78..536406f 100644 --- a/SCLAlertView.xcodeproj/project.pbxproj +++ b/SCLAlertView.xcodeproj/project.pbxproj @@ -14,9 +14,11 @@ 9E124F1B1C9EA303001A4972 /* SCLAlertViewInitTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9E124F1A1C9EA303001A4972 /* SCLAlertViewInitTests.swift */; }; 9E124F1D1C9EA6B5001A4972 /* SCLTextFieldTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9E124F1C1C9EA6B5001A4972 /* SCLTextFieldTests.swift */; }; 9E47417F1CA1DABE00F95B05 /* SCLButtonTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9E47417E1CA1DABE00F95B05 /* SCLButtonTests.swift */; }; + 9EAEFBC51CC2AA6600BA87FB /* SCLExtensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9EAEFBC41CC2AA6600BA87FB /* SCLExtensions.swift */; }; 9EE073151C9D7F4C002B43FD /* SCLAlertViewPropertiesTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9EE073131C9D7F4C002B43FD /* SCLAlertViewPropertiesTests.swift */; }; 9EE073161C9D7F4C002B43FD /* SCLAlertViewStyleTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9EE073141C9D7F4C002B43FD /* SCLAlertViewStyleTests.swift */; }; 9EE073171C9D7F6B002B43FD /* SCLAlertView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 70264F171B0F592500B32B18 /* SCLAlertView.swift */; }; + 9EE99F911CA6B2320090F845 /* SCLPublicConstructorsTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9EE99F901CA6B2320090F845 /* SCLPublicConstructorsTest.swift */; }; /* End PBXBuildFile section */ /* Begin PBXContainerItemProxy section */ @@ -40,8 +42,10 @@ 9E124F1A1C9EA303001A4972 /* SCLAlertViewInitTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SCLAlertViewInitTests.swift; sourceTree = ""; }; 9E124F1C1C9EA6B5001A4972 /* SCLTextFieldTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SCLTextFieldTests.swift; sourceTree = ""; }; 9E47417E1CA1DABE00F95B05 /* SCLButtonTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SCLButtonTests.swift; sourceTree = ""; }; + 9EAEFBC41CC2AA6600BA87FB /* SCLExtensions.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SCLExtensions.swift; sourceTree = ""; }; 9EE073131C9D7F4C002B43FD /* SCLAlertViewPropertiesTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SCLAlertViewPropertiesTests.swift; sourceTree = ""; }; 9EE073141C9D7F4C002B43FD /* SCLAlertViewStyleTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SCLAlertViewStyleTests.swift; sourceTree = ""; }; + 9EE99F901CA6B2320090F845 /* SCLPublicConstructorsTest.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SCLPublicConstructorsTest.swift; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -89,6 +93,7 @@ isa = PBXGroup; children = ( 70264F171B0F592500B32B18 /* SCLAlertView.swift */, + 9EAEFBC41CC2AA6600BA87FB /* SCLExtensions.swift */, 70264EFA1B0F588700B32B18 /* Supporting Files */, ); path = SCLAlertView; @@ -110,6 +115,7 @@ 9EE073141C9D7F4C002B43FD /* SCLAlertViewStyleTests.swift */, 9E124F1C1C9EA6B5001A4972 /* SCLTextFieldTests.swift */, 9E47417E1CA1DABE00F95B05 /* SCLButtonTests.swift */, + 9EE99F901CA6B2320090F845 /* SCLPublicConstructorsTest.swift */, 70264F071B0F588800B32B18 /* Supporting Files */, ); path = SCLAlertViewTests; @@ -231,6 +237,7 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( + 9EAEFBC51CC2AA6600BA87FB /* SCLExtensions.swift in Sources */, 70264F181B0F592500B32B18 /* SCLAlertView.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; @@ -241,6 +248,7 @@ files = ( 9E47417F1CA1DABE00F95B05 /* SCLButtonTests.swift in Sources */, 9EE073151C9D7F4C002B43FD /* SCLAlertViewPropertiesTests.swift in Sources */, + 9EE99F911CA6B2320090F845 /* SCLPublicConstructorsTest.swift in Sources */, 9EE073161C9D7F4C002B43FD /* SCLAlertViewStyleTests.swift in Sources */, 9E124F1D1C9EA6B5001A4972 /* SCLTextFieldTests.swift in Sources */, 9E124F1B1C9EA303001A4972 /* SCLAlertViewInitTests.swift in Sources */, diff --git a/SCLAlertView/SCLAlertView.swift b/SCLAlertView/SCLAlertView.swift index 3a5a765..114d158 100644 --- a/SCLAlertView/SCLAlertView.swift +++ b/SCLAlertView/SCLAlertView.swift @@ -181,10 +181,10 @@ public class SCLAlertView: UIViewController { viewText.textContainer.lineFragmentPadding = 0; viewText.font = UIFont(name: kDefaultFont, size:14) // Colours - contentView.backgroundColor = UIColorFromRGB(0xFFFFFF) - labelTitle.textColor = UIColorFromRGB(0x4D4D4D) - viewText.textColor = UIColorFromRGB(0x4D4D4D) - contentView.layer.borderColor = UIColorFromRGB(0xCCCCCC).CGColor + contentView.backgroundColor = 0xFFFFFF.toUIColor() + labelTitle.textColor = 0x4D4D4D.toUIColor() + viewText.textColor = 0x4D4D4D.toUIColor() + contentView.layer.borderColor = 0xCCCCCC.toCGColor() //Gesture Recognizer for tapping outside the textinput let tapGesture = UITapGestureRecognizer(target: self, action: #selector(SCLAlertView.tapped(_:))) tapGesture.numberOfTapsRequired = 1 @@ -449,7 +449,7 @@ public class SCLAlertView: UIViewController { viewColor = UIColor() var iconImage: UIImage? let colorInt = colorStyle ?? style.defaultColorInt - viewColor = UIColorFromRGB(colorInt) + viewColor = colorInt.toUIColor() // Icon style switch style { case .Success: @@ -536,7 +536,7 @@ public class SCLAlertView: UIViewController { } for btn in buttons { btn.backgroundColor = viewColor - btn.setTitleColor(UIColorFromRGB(colorTextButton ?? 0xFFFFFF), forState:UIControlState.Normal) + btn.setTitleColor(colorTextButton?.toUIColor() ?? 0xFFFFFF.toUIColor(), forState:UIControlState.Normal) } // Adding duration @@ -589,16 +589,6 @@ public class SCLAlertView: UIViewController { return defaultImage } } - - // Helper function to convert from RGB to UIColor - func UIColorFromRGB(rgbValue: UInt) -> UIColor { - return UIColor( - red: CGFloat((rgbValue & 0xFF0000) >> 16) / 255.0, - green: CGFloat((rgbValue & 0x00FF00) >> 8) / 255.0, - blue: CGFloat(rgbValue & 0x0000FF) / 255.0, - alpha: CGFloat(1.0) - ) - } } // ------------------------------------ diff --git a/SCLAlertView/SCLExtensions.swift b/SCLAlertView/SCLExtensions.swift new file mode 100644 index 0000000..a999e2d --- /dev/null +++ b/SCLAlertView/SCLExtensions.swift @@ -0,0 +1,41 @@ +// +// SCLExtensions.swift +// SCLAlertView +// +// Created by Christian Cabarrocas on 16/04/16. +// Copyright © 2016 Alexey Poimtsev. All rights reserved. +// + +import UIKit + +extension Int { + + func toUIColor() -> UIColor { + return UIColor( + red: CGFloat((self & 0xFF0000) >> 16) / 255.0, + green: CGFloat((self & 0x00FF00) >> 8) / 255.0, + blue: CGFloat(self & 0x0000FF) / 255.0, + alpha: CGFloat(1.0) + ) + } + + func toCGColor() -> CGColor { + return self.toUIColor().CGColor + } +} + +extension UInt { + + func toUIColor() -> UIColor { + return UIColor( + red: CGFloat((self & 0xFF0000) >> 16) / 255.0, + green: CGFloat((self & 0x00FF00) >> 8) / 255.0, + blue: CGFloat(self & 0x0000FF) / 255.0, + alpha: CGFloat(1.0) + ) + } + + func toCGColor() -> CGColor { + return self.toUIColor().CGColor + } +} \ No newline at end of file diff --git a/SCLAlertViewTests/SCLPublicConstructorsTest.swift b/SCLAlertViewTests/SCLPublicConstructorsTest.swift new file mode 100644 index 0000000..54bcd24 --- /dev/null +++ b/SCLAlertViewTests/SCLPublicConstructorsTest.swift @@ -0,0 +1,60 @@ +// +// SCLPublicConstructorsTest.swift +// SCLAlertView +// +// Created by Christian Cabarrocas on 26/03/16. +// Copyright © 2016 Alexey Poimtsev. All rights reserved. +// + +import XCTest + +class SCLPublicConstructorsTest: XCTestCase { + + override func setUp() { + super.setUp() + } + + override func tearDown() { + super.tearDown() + } + + func testShowSuccess() { + let image = UIImage() + let alert = SCLAlertView() + let successReturn = alert.showSuccess("testTitle", subTitle: "testSubTitle", closeButtonTitle: "testClosebutton", duration: 1.0, colorStyle: 1, colorTextButton: 1, circleIconImage: image) + XCTAssertNotNil(successReturn) + } + +} + + + +/* +public func showSuccess(title: String, subTitle: String, closeButtonTitle:String?=nil, duration:NSTimeInterval=0.0, colorStyle: UInt=SCLAlertViewStyle.Success.defaultColorInt, colorTextButton: UInt=0xFFFFFF, circleIconImage: UIImage? = nil) -> SCLAlertViewResponder { +return showTitle(title, subTitle: subTitle, duration: duration, completeText:closeButtonTitle, style: .Success, colorStyle: colorStyle, colorTextButton: colorTextButton, circleIconImage: circleIconImage) +} + +public class SCLAlertViewResponder { +let alertview: SCLAlertView + +// Initialisation and Title/Subtitle/Close functions +public init(alertview: SCLAlertView) { +self.alertview = alertview +} + +public func setTitle(title: String) { +self.alertview.labelTitle.text = title +} + +public func setSubTitle(subTitle: String) { +self.alertview.viewText.text = subTitle +} + +public func close() { +self.alertview.hideView() +} + +public func setDismissBlock(dismissBlock: DismissBlock) { +self.alertview.dismissBlock = dismissBlock +} +*/ \ No newline at end of file