diff --git a/CHANGELOG.md b/CHANGELOG.md index 6d008ad..9caa235 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,11 +1,12 @@ # SwiftyAppearance Change Log ## [Version 1.1.0](https://github.com/victor-pavlychko/SwiftyAppearance/releases/tag/1.1.0) -*Released on 2017-05-??.* +*Released on 2018-03-07.* - moved `UIView.refreshSubviewAppearance` to `UIWindow` where it belongs and renamed to `refreshAppearance` - renamed `UIApplication.refreshApplicationAppearance` to `refreshAppearance` -= added `AppearanceView` for application theming +- added `AppearanceStyle` for application theming +- cleaned up the API in favor of default parameters ## [Version 1.0.2](https://github.com/victor-pavlychko/SwiftyAppearance/releases/tag/1.0.2) *Released on 2016-11-27.* diff --git a/README.md b/README.md index 5de9b02..e735f30 100644 --- a/README.md +++ b/README.md @@ -103,32 +103,27 @@ provide proxy object to configure its properties. ### Free Functions -* `func appearance(for traits: UITraitCollection, _ block: () -> Void)` — adds traits from the collection to the scope -* `func appearance(in containerType: UIAppearanceContainer.Type, _ block: () -> Void)` — adds nested container to the scope -* `func appearance(inChain containerTypes: [UIAppearanceContainer.Type], _ block: () -> Void)` — adds chain of nested containers to the scope -* `func appearance(inAny containerTypes: [UIAppearanceContainer.Type], _ block: () -> Void)` — defines a set of nested scopes for each provided container +* `func appearance(for traitCollection: UITraitCollection? = nil, in containerTypes: [UIAppearanceContainer.Type] = [], _ block: () -> Void)` — adds traits and containers from the collection to the scope +* `func appearance(for traitCollection: UITraitCollection? = nil, inAny containerTypes: [UIAppearanceContainer.Type], _ block: () -> Void)` — adds traits and defines a set of nested scopes for each provided container -### UIAppearanceContainer Extensions +### UIAppearance and UIAppearanceContainer Extensions -* `static func appearance(_ block: () -> Void)` — adds nested container to the scope, this is equivalent to one of free functions +* `static func UIAppearanceContainer.appearance(style: AppearanceStyle = nil, for traitCollection: UITraitCollection? = nil, _ block: () -> Void)` — adds nested container to the scope optionally specifying style +* `static func UIAppearance.appearance(style: AppearanceStyle = nil, for traitCollection: UITraitCollection? = nil, _ block: (_ proxy: Self) -> Void)` — adds traits from the collection to the scope, provides appearance proxy for class with an optional style class, then adds current class as a container + if applicable -### UIAppearance Extensions +### UIWindow and UIApplication Extensions -This group of functions first extends scopes similar to what free functions do, then provides appearance proxy for `Self` class and finally defines -new scope adding `Self` as a container when applicable. +* `func UIWindow.refreshAppearance(animated: Bool)` — refreshes appearance for the window +* `func UIApplication.refreshAppearance(animated: Bool)` — refreshes appearance for all windows in the application -* `static func appearance(_ block: (_ proxy: Self) -> Void)` — provides appearance proxy for class, then adds current class as a container - if applicable -* `static func appearance(for traits: UITraitCollection, _ block: (_ proxy: Self) -> Void)` — adds traits from the collection to the scope, - provides appearance proxy for class, then adds current class as a container if applicable -* `static func appearance(in containerType: UIAppearanceContainer.Type, _ block: (_ proxy: Self) -> Void)` — adds nested container to the scope, - provides appearance proxy for class, then adds current class as a container if applicable -* `static func appearance(inChain containerTypes: [UIAppearanceContainer.Type], _ block: (_ proxy: Self) -> Void)` — adds chain of nested - containers to the scope, provides appearance proxy for class, then adds current class as a container if applicable -* `static func appearance(inAny containerTypes: [UIAppearanceContainer.Type], _ block: (_ proxy: Self) -> Void)` — defines a set of nested scopes - for each provided container, provides appearance proxy for class, then adds current class as a container if applicable - -## Installation +### UIView and UIViewController Extensions + +* `@IBInspectable public var appearanceStyleName: String` — inspectable property to set appearance style from Interface Builder +* `var appearanceStyle: AppearanceStyle` — appearance style accessor +* `func setAppearanceStyle(_ style: AppearanceStyle, animated: Bool)` — sets appearance style optionally animating the update + +## Installation ### CocoaPods diff --git a/SwiftyAppearance.xcodeproj/project.pbxproj b/SwiftyAppearance.xcodeproj/project.pbxproj index 4262731..c0c85f9 100644 --- a/SwiftyAppearance.xcodeproj/project.pbxproj +++ b/SwiftyAppearance.xcodeproj/project.pbxproj @@ -153,8 +153,8 @@ 57296DC41EB8B4CD004E434C /* AppearanceStyleExtensions.swift */, 571E483D204EA18E001D9FD9 /* AppearanceStyleHelpers.swift */, 57FED3801D8F3B48008DB72E /* UIAppearanceExtensions.swift */, - 57296DC61EB8F327004E434C /* UIWindowExtensions.swift */, 573B0E0D1F0A9BFF008609B1 /* UIApplicationExtensions.swift */, + 57296DC61EB8F327004E434C /* UIWindowExtensions.swift */, 57FED3751D8F3A9F008DB72E /* Info.plist */, ); path = SwiftyAppearance; diff --git a/SwiftyAppearance/UIAppearanceExtensions.swift b/SwiftyAppearance/UIAppearanceExtensions.swift index f67793e..7329c5c 100644 --- a/SwiftyAppearance/UIAppearanceExtensions.swift +++ b/SwiftyAppearance/UIAppearanceExtensions.swift @@ -8,10 +8,11 @@ import UIKit -/// Nested appearance scope for specified trait collection +/// Nested appearance scope for specified trait collection and container types /// /// - Parameters: -/// - traits: trait collection +/// - traitCollection: trait collection +/// - containerTypes: list of container types /// - block: appearance code block public func appearance(for traitCollection: UITraitCollection? = nil, in containerTypes: [UIAppearanceContainer.Type] = [], _ block: () -> Void) { AppearanceScope.main.push(traitCollection: traitCollection) @@ -20,10 +21,11 @@ public func appearance(for traitCollection: UITraitCollection? = nil, in contain AppearanceScope.main.pop(count: 2) } -/// Nested appearance scope for any of specified containers +/// Nested appearance scope for specified trait collection any of specified containers /// /// - Parameters: -/// - containerTypes: list of containers +/// - traitCollection: trait collection +/// - containerTypes: list of container types /// - block: appearance code block public func appearance(for traitCollection: UITraitCollection? = nil, inAny containerTypes: [UIAppearanceContainer.Type], _ block: () -> Void) { AppearanceScope.main.push(traitCollection: traitCollection) @@ -37,9 +39,12 @@ public func appearance(for traitCollection: UITraitCollection? = nil, inAny cont public extension UIAppearanceContainer { - /// Nested appearance scope for `Self` container + /// Nested appearance scope for `Self` container and trait collection /// - /// - Parameter block: appearance code block for current container + /// - Parameter + /// - style: appearance style for this container + /// - traitCollection: trait collection + /// - block: appearance code block for current container public static func appearance(style: AppearanceStyle = nil, for traitCollection: UITraitCollection? = nil, _ block: () -> Void) { let cls = styleClass(self, styleName: style.name) AppearanceScope.main.push(traitCollection: traitCollection) @@ -55,7 +60,8 @@ public extension UIAppearance { /// nested appearance scope for `Self` container with specified trait collection /// /// - Parameters: - /// - traits: trait collections + /// - style: appearance style for current class + /// - traitCollection: trait collections /// - block: appearance code block for current container /// - proxy: appearance proxy to configure public static func appearance(style: AppearanceStyle = nil, for traitCollection: UITraitCollection? = nil, _ block: (_ proxy: Self) -> Void) { @@ -80,7 +86,8 @@ public extension UIAppearance where Self: UIAppearanceContainer { /// nested appearance scope for `Self` container with specified trait collection /// /// - Parameters: - /// - traits: trait collections + /// - style: appearance style for current class + /// - traitCollection: trait collections /// - block: appearance code block for current container /// - proxy: appearance proxy to configure public static func appearance(style: AppearanceStyle = nil, for traitCollection: UITraitCollection? = nil, _ block: (_ proxy: Self) -> Void) { diff --git a/SwiftyAppearance/UIApplicationExtensions.swift b/SwiftyAppearance/UIApplicationExtensions.swift index bab1877..30d01bd 100644 --- a/SwiftyAppearance/UIApplicationExtensions.swift +++ b/SwiftyAppearance/UIApplicationExtensions.swift @@ -10,10 +10,8 @@ import UIKit public extension NSNotification.Name { - /// <#Description#> public static let SwiftyAppearanceWillRefreshApplication = NSNotification.Name(rawValue: "SwiftyAppearanceWillRefreshApplicationNotification") - /// <#Description#> public static let SwiftyAppearanceDidRefreshApplication = NSNotification.Name(rawValue: "SwiftyAppearanceDidRefreshApplicationNotification") } @@ -25,9 +23,9 @@ public extension UIApplication { } } - /// <#Description#> + /// Refreshes appearance for all windows in the application /// - /// - Parameter animated: <#animated description#> + /// - Parameter animated: if the refresh should be animated public func refreshAppearance(animated: Bool) { NotificationCenter.default.post(name: .SwiftyAppearanceWillRefreshApplication, object: self) UIView.animate(withDuration: animated ? 0.25 : 0, animations: { diff --git a/SwiftyAppearance/UIWindowExtensions.swift b/SwiftyAppearance/UIWindowExtensions.swift index d52a85e..9aaf3c4 100644 --- a/SwiftyAppearance/UIWindowExtensions.swift +++ b/SwiftyAppearance/UIWindowExtensions.swift @@ -10,10 +10,8 @@ import UIKit public extension NSNotification.Name { - /// <#Description#> public static let SwiftyAppearanceWillRefreshWindow = NSNotification.Name(rawValue: "SwiftyAppearanceWillRefreshWindowNotification") - /// <#Description#> public static let SwiftyAppearanceDidRefreshWindow = NSNotification.Name(rawValue: "SwiftyAppearanceDidRefreshWindowNotification") } @@ -29,9 +27,9 @@ public extension UIWindow { addConstraints(constraints) } - /// <#Description#> + /// Refreshes appearance for the window /// - /// - Parameter animated: <#animated description#> + /// - Parameter animated: if the refresh should be animated public func refreshAppearance(animated: Bool) { NotificationCenter.default.post(name: .SwiftyAppearanceWillRefreshWindow, object: self) UIView.animate(withDuration: animated ? 0.25 : 0, animations: {