Skip to content
Open
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
21 changes: 15 additions & 6 deletions ExpandingMenu/Classes/ExpandingMenuItem.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ open class ExpandingMenuItem: UIView {
titleButton.setTitle(title, for: UIControlState())
#endif
} else {
self.titleButton = self.createTitleButton(title, titleColor: self.titleColor)
self.titleButton = self.createTitleButton(title, titleColor: self.titleColor, titleFont: self.titleFont)
}
self.titleButton?.sizeToFit()
} else {
Expand All @@ -31,6 +31,12 @@ open class ExpandingMenuItem: UIView {

@objc open var titleMargin: CGFloat = 5.0

@objc open var titleFont: UIFont? {

get { return self.titleButton?.titleLabel?.font }
set { self.titleButton?.titleLabel?.font = newValue }
}

#if swift(>=4.2)
@objc open var titleColor: UIColor? {
get { return self.titleButton?.titleColor(for: UIControl.State()) }
Expand All @@ -56,7 +62,7 @@ open class ExpandingMenuItem: UIView {
fileprivate var tappedAction: (() -> Void)?

// MARK: - Initializer
public init(size: CGSize?, title: String? = nil, titleColor: UIColor? = nil, image: UIImage, highlightedImage: UIImage?, backgroundImage: UIImage?, backgroundHighlightedImage: UIImage?, itemTapped: (() -> Void)?) {
public init(size: CGSize?, title: String? = nil, titleColor: UIColor? = nil, titleFont: UIFont? = nil, image: UIImage, highlightedImage: UIImage?, backgroundImage: UIImage?, backgroundHighlightedImage: UIImage?, itemTapped: (() -> Void)?) {

// Initialize properties
//
Expand Down Expand Up @@ -114,16 +120,16 @@ open class ExpandingMenuItem: UIView {
// Configure title button
//
if let title = title {
self.titleButton = self.createTitleButton(title, titleColor: titleColor)
self.titleButton = self.createTitleButton(title, titleColor: titleColor, titleFont: titleFont)
}
}

@objc public convenience init(image: UIImage, highlightedImage: UIImage, backgroundImage: UIImage?, backgroundHighlightedImage: UIImage?, itemTapped: (() -> Void)?) {
self.init(size: nil, title: nil, image: image, highlightedImage: highlightedImage, backgroundImage: backgroundImage, backgroundHighlightedImage: backgroundHighlightedImage, itemTapped: itemTapped)
}

@objc public convenience init(title: String, titleColor: UIColor? = nil, image: UIImage, highlightedImage: UIImage, backgroundImage: UIImage?, backgroundHighlightedImage: UIImage?, itemTapped: (() -> Void)?) {
self.init(size: nil, title: title, titleColor: titleColor, image: image, highlightedImage: highlightedImage, backgroundImage: backgroundImage, backgroundHighlightedImage: backgroundHighlightedImage, itemTapped: itemTapped)
@objc public convenience init(title: String, titleColor: UIColor? = nil, titleFont: UIFont? = nil, image: UIImage, highlightedImage: UIImage, backgroundImage: UIImage?, backgroundHighlightedImage: UIImage?, itemTapped: (() -> Void)?) {
self.init(size: nil, title: title, titleColor: titleColor, titleFont: titleFont, image: image, highlightedImage: highlightedImage, backgroundImage: backgroundImage, backgroundHighlightedImage: backgroundHighlightedImage, itemTapped: itemTapped)
}

@objc public convenience init(size: CGSize, image: UIImage, highlightedImage: UIImage, backgroundImage: UIImage?, backgroundHighlightedImage: UIImage?, itemTapped: (() -> Void)?) {
Expand All @@ -137,7 +143,7 @@ open class ExpandingMenuItem: UIView {
}

// MARK: - Title Button
fileprivate func createTitleButton(_ title: String, titleColor: UIColor? = nil) -> UIButton {
fileprivate func createTitleButton(_ title: String, titleColor: UIColor? = nil, titleFont: UIFont? = nil) -> UIButton {
let button = UIButton()
#if swift(>=4.2)
button.setTitle(title, for: UIControl.State())
Expand All @@ -146,6 +152,9 @@ open class ExpandingMenuItem: UIView {
button.setTitle(title, for: UIControlState())
button.setTitleColor(titleColor, for: UIControlState())
#endif

button.titleLabel?.font = titleFont

button.sizeToFit()

button.addTarget(self, action: #selector(tapped), for: .touchUpInside)
Expand Down