|
| 1 | +import Foundation |
| 2 | +import UIKit |
| 3 | +import WordPressShared.WPFontManager |
| 4 | + |
| 5 | +open class NavigationTitleView: UIView { |
| 6 | + @objc public let titleLabel = UILabel(frame: defaultTitleFrame) |
| 7 | + @objc public let subtitleLabel = UILabel(frame: defaultSubtitleFrame) |
| 8 | + |
| 9 | + |
| 10 | + // MARK: - UIView's Methods |
| 11 | + convenience init() { |
| 12 | + self.init(frame: NavigationTitleView.defaultViewFrame) |
| 13 | + } |
| 14 | + |
| 15 | + @objc convenience init(title: String?, subtitle: String?) { |
| 16 | + self.init() |
| 17 | + titleLabel.text = title ?? String() |
| 18 | + subtitleLabel.text = subtitle ?? String() |
| 19 | + } |
| 20 | + |
| 21 | + override init(frame: CGRect) { |
| 22 | + super.init(frame: frame) |
| 23 | + setupSubviews() |
| 24 | + } |
| 25 | + |
| 26 | + required public init(coder aDecoder: NSCoder) { |
| 27 | + super.init(coder: aDecoder)! |
| 28 | + setupSubviews() |
| 29 | + } |
| 30 | + |
| 31 | + |
| 32 | + // MARK: - Helpers |
| 33 | + fileprivate func setupSubviews() { |
| 34 | + titleLabel.font = WPFontManager.systemSemiBoldFont(ofSize: NavigationTitleView.defaultTitleFontSize) |
| 35 | + titleLabel.textColor = .white |
| 36 | + titleLabel.textAlignment = .center |
| 37 | + titleLabel.backgroundColor = .clear |
| 38 | + titleLabel.autoresizingMask = .flexibleWidth |
| 39 | + |
| 40 | + subtitleLabel.font = WPFontManager.systemRegularFont(ofSize: NavigationTitleView.defaultSubtitleFontSize) |
| 41 | + subtitleLabel.textColor = .white |
| 42 | + subtitleLabel.textAlignment = .center |
| 43 | + subtitleLabel.backgroundColor = .clear |
| 44 | + subtitleLabel.autoresizingMask = .flexibleWidth |
| 45 | + |
| 46 | + backgroundColor = UIColor.clear |
| 47 | + autoresizingMask = [.flexibleWidth, .flexibleBottomMargin, .flexibleTopMargin] |
| 48 | + clipsToBounds = true |
| 49 | + |
| 50 | + addSubview(titleLabel) |
| 51 | + addSubview(subtitleLabel) |
| 52 | + } |
| 53 | + |
| 54 | + // MARK: - Static Constants |
| 55 | + fileprivate static let defaultViewFrame = CGRect(x: 0.0, y: 0.0, width: 200.0, height: 35.0) |
| 56 | + |
| 57 | + fileprivate static let defaultTitleFontSize = CGFloat(15) |
| 58 | + fileprivate static let defaultTitleFrame = CGRect(x: 0.0, y: 0.0, width: 200.0, height: 19.0) |
| 59 | + |
| 60 | + fileprivate static let defaultSubtitleFontSize = CGFloat(10) |
| 61 | + fileprivate static let defaultSubtitleFrame = CGRect(x: 0.0, y: 19.0, width: 200.0, height: 16.0) |
| 62 | +} |
0 commit comments