diff --git a/Example/Example/View Controllers/Helper/PopMenuExamples.swift b/Example/Example/View Controllers/Helper/PopMenuExamples.swift index 482489b..9c50045 100644 --- a/Example/Example/View Controllers/Helper/PopMenuExamples.swift +++ b/Example/Example/View Controllers/Helper/PopMenuExamples.swift @@ -117,10 +117,10 @@ final class PopMenuExamples { } /// PopMenu with separator line. - func popMenuSeparatorLine(_ separatorLineHidden: Bool) -> PopMenuViewController { + func popMenuSeparatorLine(_ separatorStyle: PopMenuActionSeparator) -> PopMenuViewController { let popMenu = popMenuTextAndImage() - popMenu.appearance.popMenuItemSeparatorHidden = separatorLineHidden + popMenu.appearance.popMenuItemSeparator = separatorStyle return popMenu } diff --git a/Example/Example/View Controllers/RootViewController.swift b/Example/Example/View Controllers/RootViewController.swift index 061b6fb..7f76faa 100644 --- a/Example/Example/View Controllers/RootViewController.swift +++ b/Example/Example/View Controllers/RootViewController.swift @@ -179,7 +179,7 @@ extension RootViewController { case (2, 10): popMenu = examples.popMenuCustomStatusBarStyle(.default) case (2, 11): - popMenu = examples.popMenuSeparatorLine(false) + popMenu = examples.popMenuSeparatorLine(.fill()) case (3, 0): let cell = tableView.cellForRow(at: indexPath)! popMenu = examples.popMenuStandard(cell) diff --git a/PopMenu.xcodeproj/project.pbxproj b/PopMenu.xcodeproj/project.pbxproj index e29edc5..d5c7478 100644 --- a/PopMenu.xcodeproj/project.pbxproj +++ b/PopMenu.xcodeproj/project.pbxproj @@ -17,7 +17,6 @@ 9D397AD720805F9900C58037 /* PopMenuViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9D397AD620805F9900C58037 /* PopMenuViewController.swift */; }; 9D397AF32080885F00C58037 /* PopMenuPresentAnimationController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9D397AF22080885F00C58037 /* PopMenuPresentAnimationController.swift */; }; 9D397AF52080887600C58037 /* PopMenuDismissAnimationController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9D397AF42080887600C58037 /* PopMenuDismissAnimationController.swift */; }; - 9D397AFA2080A13300C58037 /* PopMenuColor.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9D397AF92080A13300C58037 /* PopMenuColor.swift */; }; 9D397AFD2080A5F000C58037 /* PopMenuAppearance.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9D397AFC2080A5F000C58037 /* PopMenuAppearance.swift */; }; 9D397AFF2080AB9200C58037 /* PopMenuGradientView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9D397AFE2080AB9200C58037 /* PopMenuGradientView.swift */; }; 9D91B30A208207B30029ACAD /* UIView+Shadows.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9D91B309208207B30029ACAD /* UIView+Shadows.swift */; }; @@ -49,7 +48,6 @@ 9D397AD620805F9900C58037 /* PopMenuViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PopMenuViewController.swift; sourceTree = ""; }; 9D397AF22080885F00C58037 /* PopMenuPresentAnimationController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PopMenuPresentAnimationController.swift; sourceTree = ""; }; 9D397AF42080887600C58037 /* PopMenuDismissAnimationController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PopMenuDismissAnimationController.swift; sourceTree = ""; }; - 9D397AF92080A13300C58037 /* PopMenuColor.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PopMenuColor.swift; sourceTree = ""; }; 9D397AFC2080A5F000C58037 /* PopMenuAppearance.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PopMenuAppearance.swift; sourceTree = ""; }; 9D397AFE2080AB9200C58037 /* PopMenuGradientView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PopMenuGradientView.swift; sourceTree = ""; }; 9D91B309208207B30029ACAD /* UIView+Shadows.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UIView+Shadows.swift"; sourceTree = ""; }; @@ -131,7 +129,6 @@ children = ( 9D397AF62080A06200C58037 /* Helpers */, 9D397AD420805F4D00C58037 /* PopMenuManager.swift */, - 9D397AF92080A13300C58037 /* PopMenuColor.swift */, 9D397AFC2080A5F000C58037 /* PopMenuAppearance.swift */, ); path = Classes; @@ -280,7 +277,6 @@ 9D397AF32080885F00C58037 /* PopMenuPresentAnimationController.swift in Sources */, 9D397AFD2080A5F000C58037 /* PopMenuAppearance.swift in Sources */, 9D397AF52080887600C58037 /* PopMenuDismissAnimationController.swift in Sources */, - 9D397AFA2080A13300C58037 /* PopMenuColor.swift in Sources */, 9D397AD720805F9900C58037 /* PopMenuViewController.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; diff --git a/PopMenu/Classes/PopMenuAppearance.swift b/PopMenu/Classes/PopMenuAppearance.swift index e94e861..275077f 100644 --- a/PopMenu/Classes/PopMenuAppearance.swift +++ b/PopMenu/Classes/PopMenuAppearance.swift @@ -8,6 +8,12 @@ import UIKit +#if os(macOS) +public typealias Color = NSColor +#else +public typealias Color = UIColor +#endif + /// Appearance for PopMenu. /// Use for configuring custom styles and looks. final public class PopMenuAppearance: NSObject { @@ -26,9 +32,9 @@ final public class PopMenuAppearance: NSObject { /// How tall each action is. public var popMenuActionHeight: CGFloat = 50 - - /// Visibility of the separator line between actions. - public var popMenuItemSeparatorHidden: Bool = true + + /// The separator style for each action. + public var popMenuItemSeparator: PopMenuActionSeparator = .none() /// The status bar style of the pop menu. public var popMenuStatusBarStyle: UIStatusBarStyle? @@ -75,3 +81,81 @@ public struct PopMenuBackgroundStyle { } } + +/// Color structure for PopMenu color styles. +public struct PopMenuColor { + + /// Background color instance. + public var backgroundColor: PopMenuActionBackgroundColor + + /// Action tint color instance. + public var actionColor: PopMenuActionColor + + /// Compose the color. + public static func configure(background: PopMenuActionBackgroundColor, action: PopMenuActionColor) -> PopMenuColor { + return PopMenuColor(backgroundColor: background, actionColor: action) + } + + /// Get default background and action color. + public static func `default`() -> PopMenuColor { + return PopMenuColor(backgroundColor: .gradient(fill: #colorLiteral(red: 0.168627451, green: 0.168627451, blue: 0.168627451, alpha: 1), #colorLiteral(red: 0.2156862745, green: 0.2156862745, blue: 0.2156862745, alpha: 1)), actionColor: .tint(.white)) + } + +} + +/// Background color structure to control PopMenu backgrounds. +public struct PopMenuActionBackgroundColor { + + /// All colors (only one if solid color, or else it's gradient) + public let colors: [Color] + + /// Fill an only solid color into the colors palette. + public static func solid(fill color: Color) -> PopMenuActionBackgroundColor { + return .init(colors: [color]) + } + + /// Fill gradient colors into the colors palette. + public static func gradient(fill colors: Color...) -> PopMenuActionBackgroundColor { + return .init(colors: colors) + } + +} + +/// Action color structure to control PopMenu actions. +public struct PopMenuActionColor { + + /// Tint color. + public let color: Color + + /// Get action's color instance with given color. + public static func tint(_ color: Color) -> PopMenuActionColor { + return PopMenuActionColor(color: color) + } + +} + +/// Action separator structure to control PopMenu item separators. +public struct PopMenuActionSeparator: Equatable { + + /// Height of separator. + public let height: CGFloat + + /// Color of separator. + public let color: Color + + /// Fill separator color with given color and height. + public static func fill(_ color: Color = Color.white.withAlphaComponent(0.5), height: CGFloat = 0.5) -> PopMenuActionSeparator { + return PopMenuActionSeparator(height: height, color: color) + } + + /// Get separator instance with no separator style. + public static func none() -> PopMenuActionSeparator { + return PopMenuActionSeparator(height: 0, color: .clear) + } + + /// Equatable operation. + public static func == (lhs: PopMenuActionSeparator, rhs: PopMenuActionSeparator) -> Bool { + return lhs.color == rhs.color && lhs.height == rhs.height + } + +} diff --git a/PopMenu/Classes/PopMenuColor.swift b/PopMenu/Classes/PopMenuColor.swift deleted file mode 100644 index 2ecb6c3..0000000 --- a/PopMenu/Classes/PopMenuColor.swift +++ /dev/null @@ -1,67 +0,0 @@ -// -// PopMenuColor.swift -// PopMenu -// -// Created by Cali Castle on 4/13/18. -// Copyright © 2018 PopMenu. All rights reserved. -// - -import UIKit - -#if os(macOS) -public typealias Color = NSColor -#else -public typealias Color = UIColor -#endif - -/// Color structure for PopMenu color styles. -public struct PopMenuColor { - - /// Background color instance. - public var backgroundColor: PopMenuActionBackgroundColor - - /// Action tint color instance. - public var actionColor: PopMenuActionColor - - /// Compose the color. - public static func configure(background: PopMenuActionBackgroundColor, action: PopMenuActionColor) -> PopMenuColor { - return PopMenuColor(backgroundColor: background, actionColor: action) - } - - /// Get default background and action color. - public static func `default`() -> PopMenuColor { - return PopMenuColor(backgroundColor: .gradient(fill: #colorLiteral(red: 0.168627451, green: 0.168627451, blue: 0.168627451, alpha: 1), #colorLiteral(red: 0.2156862745, green: 0.2156862745, blue: 0.2156862745, alpha: 1)), actionColor: .tint(.white)) - } - -} - -/// Background color structure to control PopMenu backgrounds. -public struct PopMenuActionBackgroundColor { - - /// All colors (only one if solid color, or else it's gradient) - public let colors: [Color] - - /// Fill an only solid color into the colors palette. - public static func solid(fill color: Color) -> PopMenuActionBackgroundColor { - return .init(colors: [color]) - } - - /// Fill gradient colors into the colors palette. - public static func gradient(fill colors: Color...) -> PopMenuActionBackgroundColor { - return .init(colors: colors) - } - -} - -/// Action color structure to control PopMenu actions. -public struct PopMenuActionColor { - - /// Tint color. - public let color: Color - - /// Get action's color instance with given color. - public static func tint(_ color: Color) -> PopMenuActionColor { - return PopMenuActionColor(color: color) - } - -} diff --git a/PopMenu/View Controller & Views/PopMenuAction.swift b/PopMenu/View Controller & Views/PopMenuAction.swift index adb9eda..8bbdb7c 100644 --- a/PopMenu/View Controller & Views/PopMenuAction.swift +++ b/PopMenu/View Controller & Views/PopMenuAction.swift @@ -199,7 +199,7 @@ public class PopMenuDefaultAction: NSObject, PopMenuAction { public func highlightActionView(_ highlight: Bool) { DispatchQueue.main.async { UIView.animate(withDuration: 0.26, delay: 0, usingSpringWithDamping: 0.6, initialSpringVelocity: 9, options: self.highlighted ? .curveEaseIn : .curveEaseOut, animations: { - self.view.transform = self.highlighted ? CGAffineTransform.identity.scaledBy(x: 1.11, y: 1.11) : .identity + self.view.transform = self.highlighted ? CGAffineTransform.identity.scaledBy(x: 1.09, y: 1.09) : .identity self.view.backgroundColor = self.highlighted ? self.backgroundColor.withAlphaComponent(0.25) : .clear }, completion: nil) } diff --git a/PopMenu/View Controller & Views/PopMenuViewController.swift b/PopMenu/View Controller & Views/PopMenuViewController.swift index b2932ce..02b102c 100644 --- a/PopMenu/View Controller & Views/PopMenuViewController.swift +++ b/PopMenu/View Controller & Views/PopMenuViewController.swift @@ -406,17 +406,18 @@ extension PopMenuViewController { actionsView.alignment = .fill actionsView.distribution = .fillEqually - for i in 0..