From 4e0f7f8ab169fa5ae05047bd96af569a48fc6926 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tra=CC=82=CC=80n=20Ngo=CC=A3c=20Ta=CC=82m=20=28VINID-KPTUD?= =?UTF-8?q?ND-MN=29?= Date: Sat, 4 May 2019 12:24:41 +0700 Subject: [PATCH 1/3] support custom font for title --- ExpandingMenu/Classes/ExpandingMenuItem.swift | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/ExpandingMenu/Classes/ExpandingMenuItem.swift b/ExpandingMenu/Classes/ExpandingMenuItem.swift index ec15f1d..0e20905 100644 --- a/ExpandingMenu/Classes/ExpandingMenuItem.swift +++ b/ExpandingMenu/Classes/ExpandingMenuItem.swift @@ -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()) } From 803803e8022651e5483800827660630095ae2719 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tra=CC=82=CC=80n=20Ngo=CC=A3c=20Ta=CC=82m=20=28VINID-KPTUD?= =?UTF-8?q?ND-MN=29?= Date: Sat, 4 May 2019 15:22:26 +0700 Subject: [PATCH 2/3] fix crash --- ExpandingMenu/Classes/ExpandingMenuItem.swift | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/ExpandingMenu/Classes/ExpandingMenuItem.swift b/ExpandingMenu/Classes/ExpandingMenuItem.swift index 0e20905..7f9e3ed 100644 --- a/ExpandingMenu/Classes/ExpandingMenuItem.swift +++ b/ExpandingMenu/Classes/ExpandingMenuItem.swift @@ -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 { @@ -62,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 // @@ -120,7 +120,7 @@ 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) } } @@ -128,8 +128,8 @@ open class ExpandingMenuItem: UIView { 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)?) { @@ -143,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()) @@ -154,6 +154,7 @@ open class ExpandingMenuItem: UIView { #endif button.sizeToFit() + button.titleLabel?.font = titleFont button.addTarget(self, action: #selector(tapped), for: .touchUpInside) return button From 8efd9b9a7d4ddbf62609284637787c56660ae107 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tra=CC=82=CC=80n=20Ngo=CC=A3c=20Ta=CC=82m=20=28VINID-KPTUD?= =?UTF-8?q?ND-MN=29?= Date: Sat, 4 May 2019 15:47:40 +0700 Subject: [PATCH 3/3] fix size title --- ExpandingMenu/Classes/ExpandingMenuItem.swift | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/ExpandingMenu/Classes/ExpandingMenuItem.swift b/ExpandingMenu/Classes/ExpandingMenuItem.swift index 7f9e3ed..8d01353 100644 --- a/ExpandingMenu/Classes/ExpandingMenuItem.swift +++ b/ExpandingMenu/Classes/ExpandingMenuItem.swift @@ -152,9 +152,11 @@ open class ExpandingMenuItem: UIView { button.setTitle(title, for: UIControlState()) button.setTitleColor(titleColor, for: UIControlState()) #endif - button.sizeToFit() button.titleLabel?.font = titleFont + + button.sizeToFit() + button.addTarget(self, action: #selector(tapped), for: .touchUpInside) return button