Skip to content

Commit

Permalink
Preferred text color customization (#305)
Browse files Browse the repository at this point in the history
Add preferredTextColor to AlertVisualStyle

Co-authored-by: Scott Berrevoets <[email protected]>
  • Loading branch information
qchenqizhi and sberrevoets authored Apr 30, 2020
1 parent eb594f6 commit 57e8dff
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions Source/AlertVisualStyle.swift
Original file line number Diff line number Diff line change
Expand Up @@ -94,10 +94,14 @@ open class AlertVisualStyle: NSObject {
@objc
public var textFieldMargins = UIEdgeInsets(top: 4, left: 4, bottom: 4, right: 4)

/// The color for a nondestructive action's text
/// The color for a normal action's text
@objc
public var normalTextColor: UIColor?

/// The color for a preferred action's text. If `nil`, `normalTextColor` is used.
@objc
public var preferredTextColor: UIColor?

/// The color for a destructive action's text
@objc
public var destructiveTextColor = UIColor.red
Expand Down Expand Up @@ -177,7 +181,13 @@ open class AlertVisualStyle: NSObject {
/// - returns: The text color, or nil to use the alert's `tintColor`.
@objc
open func textColor(for action: AlertAction?) -> UIColor? {
return action?.style == .destructive ? self.destructiveTextColor : self.normalTextColor
if action?.style == .destructive {
return self.destructiveTextColor
} else if action?.style == .preferred {
return self.preferredTextColor ?? self.normalTextColor
} else {
return self.normalTextColor
}
}

/// The font for a given action.
Expand Down

0 comments on commit 57e8dff

Please sign in to comment.