Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix a crash when using with SPM and added more ui customisation values #37

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ let package = Package(
.target(
name: "SwiftyMenu",
dependencies: ["SnapKit"],
path: "SwiftyMenu"
path: "SwiftyMenu",
resources: [.process("Assets")]
),
],
swiftLanguageVersions: [.v5]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,11 @@ public extension SwiftyMenuAttributes {
case value(isEnabled: Bool, image: UIImage? = nil)

var arrowStyleValues: (isEnabled: Bool, image: UIImage?) {
#if SWIFT_PACKAGE
let frameworkBundle = Bundle.module
#else
let frameworkBundle = Bundle(for: SwiftyMenu.self)
#endif
let defaultImage = UIImage(named: "downArrow", in: frameworkBundle, compatibleWith: nil)!

switch self {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,20 @@ public extension SwiftyMenuAttributes {
enum HeaderStyle {

/** Row with background color */
case value(backgroundColor: UIColor, height: Int)
case value(backgroundColor: UIColor, contentHorizontalAlignment: UIControl.ContentHorizontalAlignment = Self.defaultContentHorizontalAlignment, height: Int)

var headerStyleValues: (backgroundColor: UIColor, height: Int) {
var headerStyleValues: (backgroundColor: UIColor, contentHorizontalAlignment: UIControl.ContentHorizontalAlignment, height: Int) {
switch self {
case let .value(backgroundColor, height):
return (backgroundColor: backgroundColor, height: height)
case let .value(backgroundColor, contentHorizontalAlignment, height):
return (backgroundColor: backgroundColor, contentHorizontalAlignment: contentHorizontalAlignment, height: height)
}
}

public static var defaultContentHorizontalAlignment: UIControl.ContentHorizontalAlignment {
if #available(iOS 11.0, *) {
return .leading
} else {
return .left
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,14 @@ public extension SwiftyMenuAttributes {

case `default`

case value(color: UIColor, separator: String, font: UIFont?)
case value(color: UIColor, selectedColor: UIColor? = nil, separator: String, font: UIFont?, alignment: NSTextAlignment = .left)

var textStyleValues: (color: UIColor, separator: String, font: UIFont?) {
var textStyleValues: (color: UIColor, selectedColor: UIColor?, separator: String, font: UIFont?, alignment: NSTextAlignment) {
switch self {
case let .value(color, separator, font):
return (color: color, separator: separator, font: font)
case let .value(color, selectedColor, separator, font, alignment):
return (color: color, selectedColor ?? color, separator: separator, font: font, alignment: alignment)
case .default:
return (color: .black, separator: ", ", font: .systemFont(ofSize: 12))
return (color: .black, nil, separator: ", ", font: .systemFont(ofSize: 12), alignment: .left)
}
}
}
Expand Down
9 changes: 4 additions & 5 deletions SwiftyMenu/Classes/SwiftyMenu.swift
Original file line number Diff line number Diff line change
Expand Up @@ -154,19 +154,22 @@ extension SwiftyMenu: UITableViewDataSource {
cell.textLabel?.text = items[indexPath.row].displayableValue
cell.textLabel?.textColor = attributes.textStyle.textStyleValues.color
cell.textLabel?.font = attributes.textStyle.textStyleValues.font
cell.textLabel?.textAlignment = attributes.textStyle.textStyleValues.alignment
cell.tintColor = attributes.textStyle.textStyleValues.color
cell.backgroundColor = attributes.rowStyle.rowStyleValues.backgroundColor
cell.selectionStyle = .none

if attributes.multiSelect.isEnabled {
if selectedIndecis[indexPath.row] != nil {
cell.textLabel?.textColor = attributes.textStyle.textStyleValues.selectedColor
cell.accessoryType = attributes.accessory.isEnabled ? .checkmark : .none
cell.backgroundColor = attributes.rowStyle.rowStyleValues.selectedColor
} else {
cell.accessoryType = .none
}
} else {
if indexPath.row == selectedIndex {
cell.textLabel?.textColor = attributes.textStyle.textStyleValues.selectedColor
cell.accessoryType = attributes.accessory.isEnabled ? .checkmark : .none
cell.backgroundColor = attributes.rowStyle.rowStyleValues.selectedColor
} else {
Expand Down Expand Up @@ -304,11 +307,7 @@ extension SwiftyMenu {
selectButton.setImage(arrow, for: .normal)
}

if #available(iOS 11.0, *) {
selectButton.contentHorizontalAlignment = .leading
} else {
selectButton.contentHorizontalAlignment = .left
}
selectButton.contentHorizontalAlignment = attributes.headerStyle.headerStyleValues.contentHorizontalAlignment

selectButton.addTarget(self, action: #selector(handleMenuState), for: .touchUpInside)
}
Expand Down