diff --git a/.swift-version b/.swift-version new file mode 100644 index 00000000..c0943d3e --- /dev/null +++ b/.swift-version @@ -0,0 +1 @@ +2.3 \ No newline at end of file diff --git a/PasscodeLock.podspec b/PasscodeLock.podspec deleted file mode 100755 index f27b3db6..00000000 --- a/PasscodeLock.podspec +++ /dev/null @@ -1,21 +0,0 @@ -Pod::Spec.new do |s| -s.name = 'PasscodeLock' -s.version = '1.0.1' -s.license = { :type => "MIT", :file => 'LICENSE.txt' } -s.summary = 'An iOS passcode lock with Touch ID authentication written in Swift.' -s.homepage = 'https://github.com/yankodimitrov/SwiftPasscodeLock' -s.authors = { 'Yanko Dimitrov' => '' } -s.source = { :git => 'https://github.com/yankodimitrov/SwiftPasscodeLock.git' } - -s.ios.deployment_target = '8.0' - -s.source_files = 'PasscodeLock/*.{h,swift}', - 'PasscodeLock/*/*.{swift}' - -s.resources = [ - 'PasscodeLock/Views/PasscodeLockView.xib', - 'PasscodeLock/en.lproj/*' - ] - -s.requires_arc = true -end \ No newline at end of file diff --git a/PasscodeLock/Functions.swift b/PasscodeLock/Functions.swift index 9e9cec25..6b61c4bd 100644 --- a/PasscodeLock/Functions.swift +++ b/PasscodeLock/Functions.swift @@ -24,3 +24,7 @@ func bundleForResource(name: String, ofType type: String) -> NSBundle { return NSBundle(forClass: PasscodeLock.self) } + +func defaultCustomColor() -> UIColor { + return UIColor(red: 0, green: 100/255, blue: 165/255, alpha: 1) +} diff --git a/PasscodeLock/PasscodeLock/ChangePasscodeState.swift b/PasscodeLock/PasscodeLock/ChangePasscodeState.swift index da097c7b..066d990e 100644 --- a/PasscodeLock/PasscodeLock/ChangePasscodeState.swift +++ b/PasscodeLock/PasscodeLock/ChangePasscodeState.swift @@ -10,31 +10,34 @@ import Foundation struct ChangePasscodeState: PasscodeLockStateType { - let title: String - let description: String + let title : String + let description : String let isCancellableAction = true - var isTouchIDAllowed = false - - init(stringsToShow: StringsToBeDisplayed?) { - - title = (stringsToShow?.passcodeLockChangeTitle ?? localizedStringFor("PasscodeLockChangeTitle", comment: "Change passcode title")) - description = (stringsToShow?.passcodeLockChangeDescription ?? localizedStringFor("PasscodeLockChangeDescription", comment: "Change passcode description")) + var isTouchIDAllowed = false + var tintColor : UIColor? + var font : UIFont? + + init(stringsToShow: StringsToBeDisplayed?, tintColor: UIColor?, font: UIFont?) { + + + let defaultColor = defaultCustomColor() + self.title = (stringsToShow?.passcodeLockChangeTitle ?? localizedStringFor("PasscodeLockChangeTitle", comment: "Change passcode title")) + self.description = (stringsToShow?.passcodeLockChangeDescription ?? localizedStringFor("PasscodeLockChangeDescription", comment: "Change passcode description")) + self.tintColor = (tintColor ?? defaultColor) + self.font = (font ?? UIFont.systemFontOfSize(16)) } - func acceptPasscode(passcode: [String], fromLock lock: PasscodeLockType, stringsToShow: StringsToBeDisplayed?) { + func acceptPasscode(passcode: [String], fromLock lock: PasscodeLockType, stringsToShow: StringsToBeDisplayed?, tintColor: UIColor?, font: UIFont?) { guard let currentPasscode = lock.repository.passcode else { return } - if passcode == currentPasscode { - - let nextState = SetPasscodeState(stringsToShow: stringsToShow) - + if (passcode == currentPasscode) { + let nextState = SetPasscodeState(stringsToShow: stringsToShow, tintColor: tintColor, font: font) lock.changeStateTo(nextState) } else { - lock.delegate?.passcodeLockDidFail(lock) } } diff --git a/PasscodeLock/PasscodeLock/ConfirmPasscodeState.swift b/PasscodeLock/PasscodeLock/ConfirmPasscodeState.swift index 22f94ad2..e676f4a2 100644 --- a/PasscodeLock/PasscodeLock/ConfirmPasscodeState.swift +++ b/PasscodeLock/PasscodeLock/ConfirmPasscodeState.swift @@ -10,24 +10,28 @@ import Foundation struct ConfirmPasscodeState: PasscodeLockStateType { - let title: String - let description: String + let title : String + let description : String let isCancellableAction = true - var isTouchIDAllowed = false + var isTouchIDAllowed = false + var tintColor : UIColor? + var font : UIFont? private var passcodeToConfirm: [String] - init(passcode: [String], stringsToShow: StringsToBeDisplayed?) { - - passcodeToConfirm = passcode - title = (stringsToShow?.passcodeLockConfirmTitle ?? localizedStringFor("PasscodeLockConfirmTitle", comment: "Confirm passcode title")) - description = (stringsToShow?.passcodeLockConfirmDescription ?? localizedStringFor("PasscodeLockConfirmDescription", comment: "Confirm passcode description")) + init(passcode: [String], stringsToShow: StringsToBeDisplayed?, tintColor: UIColor?, font: UIFont?) { + + let defaultColor = defaultCustomColor() + self.passcodeToConfirm = passcode + self.title = (stringsToShow?.passcodeLockConfirmTitle ?? localizedStringFor("PasscodeLockConfirmTitle", comment: "Confirm passcode title")) + self.description = (stringsToShow?.passcodeLockConfirmDescription ?? localizedStringFor("PasscodeLockConfirmDescription", comment: "Confirm passcode description")) + self.tintColor = (tintColor ?? defaultColor) + self.font = (font ?? UIFont.systemFontOfSize(16)) } - func acceptPasscode(passcode: [String], fromLock lock: PasscodeLockType, stringsToShow: StringsToBeDisplayed?) { + func acceptPasscode(passcode: [String], fromLock lock: PasscodeLockType, stringsToShow: StringsToBeDisplayed?, tintColor: UIColor?, font: UIFont?) { - if passcode == passcodeToConfirm { - + if (passcode == passcodeToConfirm) { lock.repository.savePasscode(passcode) lock.delegate?.passcodeLockDidSucceed(lock) @@ -35,9 +39,7 @@ struct ConfirmPasscodeState: PasscodeLockStateType { let mismatchTitle = (stringsToShow?.passcodeLockMismatchTitle ?? localizedStringFor("PasscodeLockMismatchTitle", comment: "Passcode mismatch title")) let mismatchDescription = (stringsToShow?.passcodeLockMismatchDescription ?? localizedStringFor("PasscodeLockMismatchDescription", comment: "Passcode mismatch description")) - - let nextState = SetPasscodeState(title: mismatchTitle, description: mismatchDescription) - + let nextState = SetPasscodeState(title: mismatchTitle, description: mismatchDescription, tintColor: tintColor, font: font) lock.changeStateTo(nextState) lock.delegate?.passcodeLockDidFail(lock) } diff --git a/PasscodeLock/PasscodeLock/EnterPasscodeState.swift b/PasscodeLock/PasscodeLock/EnterPasscodeState.swift index fc006f05..89b611db 100644 --- a/PasscodeLock/PasscodeLock/EnterPasscodeState.swift +++ b/PasscodeLock/PasscodeLock/EnterPasscodeState.swift @@ -12,37 +12,38 @@ public let PasscodeLockIncorrectPasscodeNotification = "passcode.lock.incorrect. struct EnterPasscodeState: PasscodeLockStateType { - let title: String - let description: String - let isCancellableAction: Bool - var isTouchIDAllowed = true + let title : String + let description : String + let isCancellableAction : Bool + var isTouchIDAllowed = true + var tintColor : UIColor? + var font : UIFont? private var inccorectPasscodeAttempts = 0 - private var isNotificationSent = false - init(allowCancellation: Bool = false, stringsToShow: StringsToBeDisplayed?) { + init(allowCancellation: Bool = false, stringsToShow: StringsToBeDisplayed?, tintColor: UIColor?, font: UIFont?) { - isCancellableAction = allowCancellation - title = (stringsToShow?.passcodeLockEnterTitle ?? localizedStringFor("PasscodeLockEnterTitle", comment: "Enter passcode title")) - description = (stringsToShow?.passcodeLockEnterDescription ?? localizedStringFor("PasscodeLockEnterDescription", comment: "Enter passcode description")) + let defaultColor = defaultCustomColor() + self.isCancellableAction = allowCancellation + self.title = (stringsToShow?.passcodeLockEnterTitle ?? localizedStringFor("PasscodeLockEnterTitle", comment: "Enter passcode title")) + self.description = (stringsToShow?.passcodeLockEnterDescription ?? localizedStringFor("PasscodeLockEnterDescription", comment: "Enter passcode description")) + self.tintColor = (tintColor ?? defaultColor) + self.font = (font ?? UIFont.systemFontOfSize(16)) } - mutating func acceptPasscode(passcode: [String], fromLock lock: PasscodeLockType, stringsToShow: StringsToBeDisplayed?) { + mutating func acceptPasscode(passcode: [String], fromLock lock: PasscodeLockType, stringsToShow: StringsToBeDisplayed?, tintColor: UIColor?, font: UIFont?) { guard let currentPasscode = lock.repository.passcode else { return } - if passcode == currentPasscode { - + if (passcode == currentPasscode) { lock.delegate?.passcodeLockDidSucceed(lock) } else { inccorectPasscodeAttempts += 1 - - if inccorectPasscodeAttempts >= lock.configuration.maximumInccorectPasscodeAttempts { - + if (inccorectPasscodeAttempts >= lock.configuration.maximumInccorectPasscodeAttempts) { postNotification() } @@ -51,13 +52,8 @@ struct EnterPasscodeState: PasscodeLockStateType { } private mutating func postNotification() { - - guard !isNotificationSent else { return } - + let center = NSNotificationCenter.defaultCenter() - center.postNotificationName(PasscodeLockIncorrectPasscodeNotification, object: nil) - - isNotificationSent = true } } diff --git a/PasscodeLock/PasscodeLock/PasscodeLock.swift b/PasscodeLock/PasscodeLock/PasscodeLock.swift index f147932f..6f9aecd9 100644 --- a/PasscodeLock/PasscodeLock/PasscodeLock.swift +++ b/PasscodeLock/PasscodeLock/PasscodeLock.swift @@ -41,15 +41,15 @@ public class PasscodeLock: PasscodeLockType { self.configuration = configuration } - public func addSign(sign: String) { + public func addSign(sign: String, stringsToBeDisplayed: StringsToBeDisplayed?, tintColor: UIColor?, font: UIFont?) { passcode.append(sign) delegate?.passcodeLock(self, addedSignAtIndex: passcode.count - 1) - if passcode.count >= configuration.passcodeLength { - - lockState.acceptPasscode(passcode, fromLock: self, stringsToShow: nil) - passcode.removeAll(keepCapacity: true) + if (passcode.count >= configuration.passcodeLength) { + + self.lockState.acceptPasscode(self.passcode, fromLock: self, stringsToShow: stringsToBeDisplayed, tintColor: tintColor, font: font) + self.passcode.removeAll(keepCapacity: true) } } diff --git a/PasscodeLock/PasscodeLock/SetPasscodeState.swift b/PasscodeLock/PasscodeLock/SetPasscodeState.swift index 3c1be804..f4853ab4 100644 --- a/PasscodeLock/PasscodeLock/SetPasscodeState.swift +++ b/PasscodeLock/PasscodeLock/SetPasscodeState.swift @@ -10,27 +10,34 @@ import Foundation struct SetPasscodeState: PasscodeLockStateType { - let title: String - let description: String + let title : String + let description : String let isCancellableAction = true - var isTouchIDAllowed = false + var isTouchIDAllowed = false + var tintColor : UIColor? + var font : UIFont? - init(title: String, description: String) { - + init(title: String, description: String, tintColor: UIColor?, font: UIFont?) { + + let defaultColor = defaultCustomColor() self.title = title self.description = description + self.tintColor = (tintColor ?? defaultColor) + self.font = (font ?? UIFont.systemFontOfSize(16)) } - init(stringsToShow: StringsToBeDisplayed?) { - - title = (stringsToShow?.passcodeLockSetTitle ?? localizedStringFor("PasscodeLockSetTitle", comment: "Set passcode title")) - description = (stringsToShow?.passcodeLockSetDescription ?? localizedStringFor("PasscodeLockSetDescription", comment: "Set passcode description")) + init(stringsToShow: StringsToBeDisplayed?, tintColor: UIColor?, font: UIFont?) { + + let defaultColor = defaultCustomColor() + self.title = (stringsToShow?.passcodeLockSetTitle ?? localizedStringFor("PasscodeLockSetTitle", comment: "Set passcode title")) + self.description = (stringsToShow?.passcodeLockSetDescription ?? localizedStringFor("PasscodeLockSetDescription", comment: "Set passcode description")) + self.tintColor = (tintColor ?? defaultColor) + self.font = (font ?? UIFont.systemFontOfSize(16)) } - func acceptPasscode(passcode: [String], fromLock lock: PasscodeLockType, stringsToShow: StringsToBeDisplayed?) { + func acceptPasscode(passcode: [String], fromLock lock: PasscodeLockType, stringsToShow: StringsToBeDisplayed?, tintColor: UIColor?, font: UIFont?) { - let nextState = ConfirmPasscodeState(passcode: passcode, stringsToShow: stringsToShow) - + let nextState = ConfirmPasscodeState(passcode: passcode, stringsToShow: stringsToShow, tintColor: tintColor, font: font) lock.changeStateTo(nextState) } } diff --git a/PasscodeLock/PasscodeLockPresenter.swift b/PasscodeLock/PasscodeLockPresenter.swift index a4a65c33..681402e9 100644 --- a/PasscodeLock/PasscodeLockPresenter.swift +++ b/PasscodeLock/PasscodeLockPresenter.swift @@ -75,14 +75,14 @@ public class PasscodeLockPresenter { passcodeLockVC = viewController } - public convenience init(mainWindow window: UIWindow?, configuration: PasscodeLockConfigurationType, stringsToShow: StringsToBeDisplayed?) { + public convenience init(mainWindow window: UIWindow?, configuration: PasscodeLockConfigurationType, stringsToShow: StringsToBeDisplayed?, tintColor: UIColor?, font: UIFont?) { - let passcodeLockVC = PasscodeLockViewController(state: .EnterPasscode, configuration: configuration, stringsToShow: stringsToShow) + let passcodeLockVC = PasscodeLockViewController(state: .EnterPasscode, configuration: configuration, stringsToShow: stringsToShow, tintColor: tintColor, font: font) self.init(mainWindow: window, configuration: configuration, viewController: passcodeLockVC) } - public func presentPasscodeLock(withImage image: UIImage? = nil, andStrings stringsToShow: StringsToBeDisplayed? = nil, dismissCompletionBlock: (() -> Void)? = nil) { + public func presentPasscodeLock(withImage image: UIImage? = nil, configuration config: PasscodeLockConfigurationType? = nil, andStrings stringsToShow: StringsToBeDisplayed? = nil, tintColor: UIColor?, font: UIFont?, dismissCompletionBlock: (() -> Void)? = nil) { guard passcodeConfiguration.repository.hasPasscode else { return } guard !isPasscodePresented else { return } @@ -95,7 +95,7 @@ public class PasscodeLockPresenter { mainWindow?.windowLevel = 1 mainWindow?.endEditing(true) - let passcodeLockVC = PasscodeLockViewController(state: .EnterPasscode, configuration: passcodeConfiguration, stringsToShow: stringsToShow) + let passcodeLockVC = PasscodeLockViewController(state: .EnterPasscode, configuration: (config ?? passcodeConfiguration), stringsToShow: stringsToShow, tintColor: tintColor, font: font) if (image != nil) { passcodeLockVC.customImage = image } diff --git a/PasscodeLock/PasscodeLockViewController.swift b/PasscodeLock/PasscodeLockViewController.swift index f050af97..25e826df 100644 --- a/PasscodeLock/PasscodeLockViewController.swift +++ b/PasscodeLock/PasscodeLockViewController.swift @@ -16,17 +16,18 @@ public class PasscodeLockViewController: UIViewController, PasscodeLockTypeDeleg case ChangePasscode case RemovePasscode - func getState(stringsToShow: StringsToBeDisplayed?) -> PasscodeLockStateType { + func getState(stringsToShow: StringsToBeDisplayed?, tintColor: UIColor?, font: UIFont?) -> PasscodeLockStateType { switch self { - case .EnterPasscode: return EnterPasscodeState(stringsToShow: stringsToShow) - case .SetPasscode: return SetPasscodeState(stringsToShow: stringsToShow) - case .ChangePasscode: return ChangePasscodeState(stringsToShow: stringsToShow) - case .RemovePasscode: return EnterPasscodeState(allowCancellation: true, stringsToShow: stringsToShow) + case .EnterPasscode: return EnterPasscodeState(stringsToShow: stringsToShow, tintColor: tintColor, font: font) + case .SetPasscode: return SetPasscodeState(stringsToShow: stringsToShow, tintColor: tintColor, font: font) + case .ChangePasscode: return ChangePasscodeState(stringsToShow: stringsToShow, tintColor: tintColor, font: font) + case .RemovePasscode: return EnterPasscodeState(allowCancellation: true, stringsToShow: stringsToShow, tintColor: tintColor, font: font) } } } + @IBOutlet public var passcodeButtons : [PasscodeSignButton]? @IBOutlet public weak var titleLabel : UILabel? @IBOutlet public weak var customImageView : UIImageView? @IBOutlet public weak var descriptionLabel : UILabel? @@ -48,13 +49,17 @@ public class PasscodeLockViewController: UIViewController, PasscodeLockTypeDeleg internal var isPlaceholdersAnimationCompleted = true private var shouldTryToAuthenticateWithBiometrics = true + private var customTintColor : UIColor? + private var font : UIFont? // MARK: - Initializers - public init(state: PasscodeLockStateType, configuration: PasscodeLockConfigurationType, animateOnDismiss: Bool = true, stringToShow: StringsToBeDisplayed?) { + public init(state: PasscodeLockStateType, configuration: PasscodeLockConfigurationType, animateOnDismiss: Bool = true, stringToShow: StringsToBeDisplayed?, tintColor: UIColor?, font: UIFont?) { self.stringsToShow = stringToShow self.animateOnDismiss = animateOnDismiss + self.font = (font ?? UIFont.systemFontOfSize(16)) + self.customTintColor = (tintColor ?? UIColor(red: 0, green: 100/255, blue: 165/255, alpha: 1)) passcodeConfiguration = configuration passcodeLock = PasscodeLock(state: state, configuration: configuration) let nibName = "PasscodeLockView" @@ -65,9 +70,9 @@ public class PasscodeLockViewController: UIViewController, PasscodeLockTypeDeleg notificationCenter = NSNotificationCenter.defaultCenter() } - public convenience init(state: LockState, configuration: PasscodeLockConfigurationType, animateOnDismiss: Bool = true, stringsToShow: StringsToBeDisplayed?) { + public convenience init(state: LockState, configuration: PasscodeLockConfigurationType, animateOnDismiss: Bool = true, stringsToShow: StringsToBeDisplayed?, tintColor: UIColor?, font: UIFont?) { - self.init(state: state.getState(stringsToShow), configuration: configuration, animateOnDismiss: animateOnDismiss, stringToShow: stringsToShow) + self.init(state: state.getState(stringsToShow, tintColor: tintColor, font: font), configuration: configuration, animateOnDismiss: animateOnDismiss, stringToShow: stringsToShow, tintColor: tintColor, font: font) } public required init(coder aDecoder: NSCoder) { @@ -82,10 +87,21 @@ public class PasscodeLockViewController: UIViewController, PasscodeLockTypeDeleg public override func viewDidLoad() { super.viewDidLoad() - - updatePasscodeView() - setupEvents() + + self.configurePasscodeButtons() + self.updatePasscodeView() + self.setupEvents() } + + private func configurePasscodeButtons() { + + self.placeholders.forEach { (passcodePlaceHolder: PasscodeSignPlaceholderView) in + if let _customTintColor = self.customTintColor { + passcodePlaceHolder.activeColor = _customTintColor + } + passcodePlaceHolder.setupView() + } + } public override func viewDidAppear(animated: Bool) { super.viewDidAppear(animated) @@ -97,11 +113,18 @@ public class PasscodeLockViewController: UIViewController, PasscodeLockTypeDeleg internal func updatePasscodeView() { - customImageView?.image = self.customImage - titleLabel?.text = passcodeLock.state.title - descriptionLabel?.text = passcodeLock.state.description - touchIDButton?.hidden = !passcodeLock.isTouchIDAllowed - touchIDButton?.setTitle((self.stringsToShow?.useTouchID ?? localizedStringFor("UseTouchId", comment: "")), forState: .Normal) + self.customImageView?.image = self.customImage + self.titleLabel?.text = passcodeLock.state.title + self.titleLabel?.font = self.font + self.titleLabel?.textColor = self.customTintColor + self.descriptionLabel?.text = passcodeLock.state.description + self.touchIDButton?.hidden = !passcodeLock.isTouchIDAllowed + self.touchIDButton?.setTitle((self.stringsToShow?.useTouchID ?? localizedStringFor("UseTouchId", comment: "")), forState: .Normal) + self.touchIDButton?.setTitleColor(self.customTintColor, forState: .Normal) + self.passcodeButtons?.forEach({ (passcodeButton: PasscodeSignButton) in + passcodeButton.tintColor = self.customTintColor + }) + self.cancelDeleteButtonSetup() } @@ -137,7 +160,7 @@ public class PasscodeLockViewController: UIViewController, PasscodeLockTypeDeleg return } - passcodeLock.addSign(sender.passcodeSign) + passcodeLock.addSign(sender.passcodeSign, stringsToBeDisplayed: self.stringsToShow, tintColor: customTintColor, font: font) } @IBAction func cancelButtonTap(sender: UIButton) { @@ -222,7 +245,7 @@ public class PasscodeLockViewController: UIViewController, PasscodeLockTypeDeleg guard (index < placeholders.count && index >= 0) else { return } - + placeholders[index].animateState(state) } @@ -269,6 +292,9 @@ public class PasscodeLockViewController: UIViewController, PasscodeLockTypeDeleg let cancelButton = ((self.passcodeLock.isPincodeEmpty == true) ? (self.stringsToShow?.cancel ?? localizedStringFor("Cancel", comment: "")) : (self.stringsToShow?.delete ?? localizedStringFor("Delete", comment: ""))) let titleForButton = ((self.passcodeLock.state.isCancellableAction == true) ? cancelButton : (self.stringsToShow?.delete ?? localizedStringFor("Delete", comment: ""))) self.cancelDeleteButton?.setTitle(titleForButton, forState: .Normal) + self.cancelDeleteButton?.setTitleColor(self.customTintColor, forState: .Normal) + self.cancelDeleteButton?.setTitleColor(self.customTintColor?.colorWithAlphaComponent(0.5), forState: .Disabled) + self.cancelDeleteButton?.titleLabel?.font = self.font if (self.passcodeLock.isPincodeEmpty == true && self.passcodeLock.state.isCancellableAction == false) { self.cancelDeleteButton?.enabled = false diff --git a/PasscodeLock/Protocols/PasscodeLockStateType.swift b/PasscodeLock/Protocols/PasscodeLockStateType.swift index 8598c1f2..59c07353 100644 --- a/PasscodeLock/Protocols/PasscodeLockStateType.swift +++ b/PasscodeLock/Protocols/PasscodeLockStateType.swift @@ -10,10 +10,11 @@ import Foundation public protocol PasscodeLockStateType { - var title: String {get} - var description: String {get} - var isCancellableAction: Bool {get} - var isTouchIDAllowed: Bool {get} + var title : String {get} + var description : String {get} + var isCancellableAction : Bool {get} + var isTouchIDAllowed : Bool {get} + var tintColor : UIColor? {get} - mutating func acceptPasscode(passcode: [String], fromLock lock: PasscodeLockType, stringsToShow: StringsToBeDisplayed?) + mutating func acceptPasscode(passcode: [String], fromLock lock: PasscodeLockType, stringsToShow: StringsToBeDisplayed?, tintColor: UIColor?, font: UIFont?) } diff --git a/PasscodeLock/Protocols/PasscodeLockType.swift b/PasscodeLock/Protocols/PasscodeLockType.swift index cd00a4c6..257d005e 100644 --- a/PasscodeLock/Protocols/PasscodeLockType.swift +++ b/PasscodeLock/Protocols/PasscodeLockType.swift @@ -17,7 +17,7 @@ public protocol PasscodeLockType { var isTouchIDAllowed: Bool {get} var isPincodeEmpty: Bool {get} - func addSign(sign: String) + func addSign(sign: String, stringsToBeDisplayed: StringsToBeDisplayed?, tintColor: UIColor?, font: UIFont?) func removeSign() func changeStateTo(state: PasscodeLockStateType) func authenticateWithBiometrics(stringsToShow: StringsToBeDisplayed?) diff --git a/PasscodeLock/Views/PasscodeLockView.xib b/PasscodeLock/Views/PasscodeLockView.xib index ed21f2c0..694aaf33 100644 --- a/PasscodeLock/Views/PasscodeLockView.xib +++ b/PasscodeLock/Views/PasscodeLockView.xib @@ -1,5 +1,5 @@ - + @@ -23,6 +23,16 @@ + + + + + + + + + + diff --git a/PasscodeLock/Views/PasscodeSignButton.swift b/PasscodeLock/Views/PasscodeSignButton.swift index 97df2716..ceb08817 100644 --- a/PasscodeLock/Views/PasscodeSignButton.swift +++ b/PasscodeLock/Views/PasscodeSignButton.swift @@ -8,96 +8,14 @@ import UIKit -//@IBDesignable public class PasscodeSignButton: UIButton { -// @IBInspectable public var passcodeSign: String = "1" - -// @IBInspectable -// public var borderColor: UIColor = UIColor.whiteColor() { -// didSet { -// setupView() -// } -// } -// -// @IBInspectable -// public var borderRadius: CGFloat = 30 { -// didSet { -// setupView() -// } -// } -// -// @IBInspectable -// public var highlightBackgroundColor: UIColor = UIColor.clearColor() { -// didSet { -// setupView() -// } -// } -// -// public override init(frame: CGRect) { -// -// super.init(frame: frame) -// -// setupView() -// setupActions() -// } -// -// public required init?(coder aDecoder: NSCoder) { -// -// super.init(coder: aDecoder) -// -// setupActions() -// } -// -// public override func intrinsicContentSize() -> CGSize { -// -// return CGSizeMake(60, 60) -// } -// -// private var defaultBackgroundColor = UIColor.clearColor() -// -// private func setupView() { -// -// layer.borderWidth = 1 -// layer.cornerRadius = layer.frame.height/2 -// layer.borderColor = borderColor.CGColor -// -// if let backgroundColor = backgroundColor { -// -// defaultBackgroundColor = backgroundColor -// } -// } -// -// private func setupActions() { -// -// addTarget(self, action: #selector(self.handleTouchDown), forControlEvents: .TouchDown) -// addTarget(self, action: #selector(self.handleTouchUp), forControlEvents: [.TouchUpInside, .TouchDragOutside, .TouchCancel]) -// } -// -// func handleTouchDown() { -// -// animateBackgroundColor(highlightBackgroundColor) -// } -// -// func handleTouchUp() { -// -// animateBackgroundColor(defaultBackgroundColor) -// } -// -// private func animateBackgroundColor(color: UIColor) { -// -// UIView.animateWithDuration( -// 0.3, -// delay: 0.0, -// usingSpringWithDamping: 1, -// initialSpringVelocity: 0.0, -// options: [.AllowUserInteraction, .BeginFromCurrentState], -// animations: { -// -// self.backgroundColor = color -// }, -// completion: nil -// ) -// } + public var customTintColor: UIColor? = UIColor(red: 0, green: 100/255, blue: 165/255, alpha: 1) + + public override func awakeFromNib() { + super.awakeFromNib() + + self.tintColor = customTintColor + } } diff --git a/PasscodeLock/Views/PasscodeSignPlaceholderView.swift b/PasscodeLock/Views/PasscodeSignPlaceholderView.swift index 42a28770..b769d230 100644 --- a/PasscodeLock/Views/PasscodeSignPlaceholderView.swift +++ b/PasscodeLock/Views/PasscodeSignPlaceholderView.swift @@ -16,28 +16,28 @@ public class PasscodeSignPlaceholderView: UIView { case Active case Error } - - @IBInspectable - public var inactiveColor: UIColor = UIColor.whiteColor() { - didSet { - setupView() - } - } - - @IBInspectable - public var activeColor: UIColor = UIColor.grayColor() { - didSet { - setupView() - } - } - - @IBInspectable - public var errorColor: UIColor = UIColor.redColor() { - didSet { - setupView() - } - } - + + @IBInspectable + public var inactiveColor: UIColor = UIColor.whiteColor() { + didSet { + self.setupView() + } + } + + @IBInspectable + public var activeColor: UIColor = UIColor.grayColor() { + didSet { + self.setupView() + } + } + + @IBInspectable + public var errorColor: UIColor = UIColor.redColor() { + didSet { + self.setupView() + } + } + public override init(frame: CGRect) { super.init(frame: frame) @@ -55,7 +55,7 @@ public class PasscodeSignPlaceholderView: UIView { return CGSizeMake(16, 16) } - private func setupView() { + func setupView() { layer.cornerRadius = 7 layer.borderWidth = 1 @@ -72,23 +72,16 @@ public class PasscodeSignPlaceholderView: UIView { } } - public func animateState(state: State) { + public func animateState(state: State, completion: (() -> Void)? = nil) { let colors = colorsForState(state) - - UIView.animateWithDuration( - 0.5, - delay: 0, - usingSpringWithDamping: 1, - initialSpringVelocity: 0, - options: [], - animations: { - - self.backgroundColor = colors.backgroundColor - self.layer.borderColor = colors.borderColor.CGColor - - }, - completion: nil - ) - } + + UIView.animateWithDuration(0.5, delay: 0, usingSpringWithDamping: 1, initialSpringVelocity: 0, options: [], animations: { [weak self] in + self?.backgroundColor = colors.backgroundColor + self?.layer.borderColor = colors.borderColor.CGColor + + }, completion: nil) + } + } + diff --git a/PasscodeLockDemo/AppDelegate.swift b/PasscodeLockDemo/AppDelegate.swift index 06a5d90f..11814561 100644 --- a/PasscodeLockDemo/AppDelegate.swift +++ b/PasscodeLockDemo/AppDelegate.swift @@ -17,14 +17,14 @@ class AppDelegate: UIResponder, UIApplicationDelegate { lazy var passcodeLockPresenter: PasscodeLockPresenter = { let configuration = PasscodeLockConfiguration() - let presenter = PasscodeLockPresenter(mainWindow: self.window, configuration: configuration, stringsToShow: nil) + let presenter = PasscodeLockPresenter(mainWindow: self.window, configuration: configuration, stringsToShow: nil, tintColor: UIColor.blueColor(), font: UIFont.italicSystemFontOfSize(16)) return presenter }() func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool { - passcodeLockPresenter.presentPasscodeLock() + passcodeLockPresenter.presentPasscodeLock(tintColor: UIColor.blueColor(), font: UIFont.italicSystemFontOfSize(16)) return true } @@ -38,7 +38,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate { // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. - passcodeLockPresenter.presentPasscodeLock() + passcodeLockPresenter.presentPasscodeLock(tintColor: UIColor.blueColor(), font: UIFont.italicSystemFontOfSize(16)) } func applicationWillEnterForeground(application: UIApplication) { diff --git a/PasscodeLockDemo/PasscodeSettingsViewController.swift b/PasscodeLockDemo/PasscodeSettingsViewController.swift index 073b9546..5bc806b1 100644 --- a/PasscodeLockDemo/PasscodeSettingsViewController.swift +++ b/PasscodeLockDemo/PasscodeSettingsViewController.swift @@ -57,11 +57,11 @@ class PasscodeSettingsViewController: UIViewController { if passcodeSwitch.on { - passcodeVC = PasscodeLockViewController(state: .SetPasscode, configuration: configuration, stringsToShow: nil) + passcodeVC = PasscodeLockViewController(state: .SetPasscode, configuration: configuration, stringsToShow: nil, tintColor: UIColor.blueColor(), font: UIFont.italicSystemFontOfSize(16)) } else { - passcodeVC = PasscodeLockViewController(state: .RemovePasscode, configuration: configuration, stringsToShow: nil) + passcodeVC = PasscodeLockViewController(state: .RemovePasscode, configuration: configuration, stringsToShow: nil, tintColor: UIColor.blueColor(), font: UIFont.italicSystemFontOfSize(16)) passcodeVC.successCallback = { lock in @@ -77,7 +77,7 @@ class PasscodeSettingsViewController: UIViewController { let repo = UserDefaultsPasscodeRepository() let config = PasscodeLockConfiguration(repository: repo) - let passcodeLock = PasscodeLockViewController(state: .ChangePasscode, configuration: config, stringsToShow: nil) + let passcodeLock = PasscodeLockViewController(state: .ChangePasscode, configuration: config, stringsToShow: nil, tintColor: UIColor.blueColor(), font: UIFont.italicSystemFontOfSize(16)) presentViewController(passcodeLock, animated: true, completion: nil) } diff --git a/SMFPasscodeLock.podspec b/SMFPasscodeLock.podspec new file mode 100755 index 00000000..42cfcd04 --- /dev/null +++ b/SMFPasscodeLock.podspec @@ -0,0 +1,31 @@ +# +# Be sure to run `pod lib lint TestLib.podspec' to ensure this is a +# valid spec before submitting. +# +# Any lines starting with a # are optional, but their use is encouraged +# To learn more about a Podspec see http://guides.cocoapods.org/syntax/podspec.html +# + +Pod::Spec.new do |s| +s.name = 'SMFPasscodeLock' +s.version = '1.0.8' +s.license = { :type => "MIT", :file => 'LICENSE.txt' } +s.summary = 'SMF Fork of PasscodeLock: An iOS passcode lock with Touch ID authentication written in Swift.' +s.homepage = 'https://github.com/smartmobilefactory/SwiftPasscodeLock' +s.source = { :git => 'https://github.com/smartmobilefactory/SwiftPasscodeLock.git', :tag => "versions/#{s.version}" } +s.authors = [{ 'Ramiro Ramirez' => '' }, { 'Yanko Dimitrov' => '' }, { 'Hans Seiffert' => '' }] + +s.ios.deployment_target = '8.0' + +s.source_files = 'PasscodeLock/*.{h,swift}', + 'PasscodeLock/*/*.{swift}' + +s.resources = [ + 'PasscodeLock/Views/PasscodeLockView.xib', + 'PasscodeLock/en.lproj/*', + 'PasscodeLock/PasscodeLockImages.xcassets', + 'PasscodeLock/PasscodeLockImages.xcassets/**/*' + ] + +s.requires_arc = true +end