diff --git a/WhatsNew.podspec b/WhatsNew.podspec index 51a26a0..3521f9d 100644 --- a/WhatsNew.podspec +++ b/WhatsNew.podspec @@ -1,6 +1,6 @@ Pod::Spec.new do |s| s.name = 'WhatsNew' - s.version = '0.2.1' + s.version = '0.3' s.summary = 'Showcase new features after an app update similar to Pages, Numbers and Keynote.' # This description is used to generate tags and improve search results. diff --git a/WhatsNew/Items/WhatsNewItem.swift b/WhatsNew/Items/WhatsNewItem.swift index a5e927d..31a9ab7 100644 --- a/WhatsNew/Items/WhatsNewItem.swift +++ b/WhatsNew/Items/WhatsNewItem.swift @@ -11,3 +11,32 @@ public enum WhatsNewItem { case text(title: String, subtitle: String) case image(title: String, subtitle: String, image: UIImage) } + +@objc public protocol WhatsNewItemCustomizable { + weak var titleLabel: UILabel! { get set } + weak var subtitleLabel: UILabel! { get set } +} + +public extension WhatsNewItemCustomizable { + + public func setDefaultFonts() { + set(titleFont: nil, subtitleFont: nil) + } + + // Default implementation. + public func set(titleFont: UIFont? = nil, subtitleFont: UIFont? = nil) { + if let titleFont = titleFont, let subtitleFont = subtitleFont { + titleLabel.font = titleFont + subtitleLabel.font = subtitleFont + return + } + // Use dynamic font size based on user preference if we're on > iOS 10. + if #available(iOS 10, *) { + titleLabel.font = UIFont.preferredFont(forTextStyle: .headline) + subtitleLabel.font = UIFont.preferredFont(forTextStyle: .body) + } else { + titleLabel.font = UIFont.systemFont(ofSize: 20, weight: .bold) + subtitleLabel.font = UIFont.systemFont(ofSize: 16, weight: .regular) + } + } +} diff --git a/WhatsNew/Items/WhatsNewItemImageView.swift b/WhatsNew/Items/WhatsNewItemImageView.swift index 10e7d1a..eb87ce7 100644 --- a/WhatsNew/Items/WhatsNewItemImageView.swift +++ b/WhatsNew/Items/WhatsNewItemImageView.swift @@ -7,17 +7,23 @@ import UIKit -class WhatsNewItemImageView: UIView, NibLoadable { +class WhatsNewItemImageView: UIView, NibLoadable, WhatsNewItemCustomizable { @IBOutlet weak var imageView: UIImageView! @IBOutlet weak var titleLabel: UILabel! @IBOutlet weak var subtitleLabel: UILabel! func set(image: UIImage, title: String, subtitle: String, textColor: UIColor) { + NotificationCenter.default.addObserver(self, selector: #selector(refreshFonts), name: NSNotification.Name.UIContentSizeCategoryDidChange, object: nil) imageView.image = image titleLabel.text = title titleLabel.textColor = textColor subtitleLabel.text = subtitle subtitleLabel.textColor = textColor + setDefaultFonts() + } + + @objc func refreshFonts() { + setDefaultFonts() } } diff --git a/WhatsNew/Items/WhatsNewItemTextView.swift b/WhatsNew/Items/WhatsNewItemTextView.swift index a68d0be..52763df 100644 --- a/WhatsNew/Items/WhatsNewItemTextView.swift +++ b/WhatsNew/Items/WhatsNewItemTextView.swift @@ -7,15 +7,21 @@ import UIKit -class WhatsNewItemTextView: UIView, NibLoadable { +class WhatsNewItemTextView: UIView, NibLoadable, WhatsNewItemCustomizable { @IBOutlet weak var titleLabel: UILabel! @IBOutlet weak var subtitleLabel: UILabel! func set(title: String, subtitle: String, textColor: UIColor) { + NotificationCenter.default.addObserver(self, selector: #selector(refreshFonts), name: NSNotification.Name.UIContentSizeCategoryDidChange, object: nil) titleLabel.text = title titleLabel.textColor = textColor subtitleLabel.text = subtitle subtitleLabel.textColor = textColor + setDefaultFonts() + } + + @objc func refreshFonts() { + setDefaultFonts() } } diff --git a/WhatsNew/Resources/WhatsNew.xib b/WhatsNew/Resources/WhatsNew.xib index 8fc0c4d..8bee79b 100644 --- a/WhatsNew/Resources/WhatsNew.xib +++ b/WhatsNew/Resources/WhatsNew.xib @@ -32,9 +32,9 @@ -