From 2a1d87665be6972e52ef34c51a7210bc6b0fa790 Mon Sep 17 00:00:00 2001 From: Dawid Drechny Date: Wed, 10 Aug 2016 20:33:28 +0200 Subject: [PATCH] Add tintColor configuration setting --- Example/ViewController.swift | 3 +++ README.md | 9 +++++++++ Source/Armchair.swift | 17 ++++++++++++++++- 3 files changed, 28 insertions(+), 1 deletion(-) diff --git a/Example/ViewController.swift b/Example/ViewController.swift index fbd0bcb..7d5703f 100644 --- a/Example/ViewController.swift +++ b/Example/ViewController.swift @@ -141,6 +141,9 @@ extension ViewController { #if os(iOS) // Explicitly disable the storeKit as the default may be true if on iOS 8 Armchair.opensInStoreKit(false) + + // This sets a custom tint color (applies only to UIAlertController). + Armchair.tintColor(UIColor.brownColor()) #endif // This sets the Affiliate code you want to use, but is not required. diff --git a/README.md b/README.md index c4db18e..fd5259f 100644 --- a/README.md +++ b/README.md @@ -329,6 +329,15 @@ Armchair.usesAnimation() -> Bool Armchair.usesAnimation(usesAnimation: Bool) ``` +The `tintColor` configuration specifies a tint color that is applied to UIAlertController when `usesAlertController` is true. Its default value is `nil`, which means that tint color is not customized. + +```swift +// GETTER +Armchair.tintColor() -> UIColor? +// SETTER +Armchair.tintColor(tintColor: UIColor?) +``` + The `usesAlertController` configuration determines whether or not Armchair uses a UIAlertController when presenting an alert on iOS 8. By default, we do not use it because the reordering of buttons is not possible in the alert controller as of iOS 8.0. It's default value is `false`. Changing this value does not affect iOS 7 at all. ```swift diff --git a/Source/Armchair.swift b/Source/Armchair.swift index 9be924d..fcb5554 100644 --- a/Source/Armchair.swift +++ b/Source/Armchair.swift @@ -359,6 +359,7 @@ public func resetDefaults() { #if os(iOS) Manager.defaultManager.usesAnimation = true + Manager.defaultManager.tintColor = nil Manager.defaultManager.usesAlertController = Manager.defaultManager.defaultUsesAlertController() Manager.defaultManager.opensInStoreKit = Manager.defaultManager.defaultOpensInStoreKit() Manager.defaultManager.willPresentModalViewClosure = nil @@ -394,7 +395,18 @@ public func resetDefaults() { public func usesAnimation(usesAnimation: Bool) { Manager.defaultManager.usesAnimation = usesAnimation } - + + /* + * Set a tint color to apply to UIAlertController + * Default => nil (the default tint color is used) + */ + public func tintColor() -> UIColor? { + return Manager.defaultManager.tintColor + } + public func tintColor(tintColor: UIColor?) { + Manager.defaultManager.tintColor = tintColor + } + /* * Set whether or not Armchair uses a UIAlertController when presenting on iOS 8 * We prefer not to use it so that the Rate button can be on the bottom and the cancel button on the top, @@ -847,6 +859,7 @@ public class Manager : ArmchairManager { #if os(iOS) private var usesAnimation: Bool = true + private var tintColor: UIColor? = nil private lazy var usesAlertController: Bool = self.defaultUsesAlertController() private lazy var opensInStoreKit: Bool = self.defaultOpensInStoreKit() @@ -1192,6 +1205,8 @@ public class Manager : ArmchairManager { topController.presentViewController(alertView, animated: usesAnimation) { print("presentViewController() completed") } + // note that tint color has to be set after the controller is presented in order to take effect (last checked in iOS 9.3) + alertView.view.tintColor = tintColor } }