|
class SubtitledNavigationTitleView: UIView { |
|
|
|
let titleLabel: UILabel = { |
|
let label = UILabel() |
|
label.adjustsFontForContentSizeCategory = true |
|
label.font = .preferredFont(forTextStyle: .headline) |
|
label.textAlignment = .center |
|
label.numberOfLines = 1 |
|
return label |
|
}() |
|
|
|
let subtitleLabel: UILabel = { |
|
let label = UILabel() |
|
label.adjustsFontForContentSizeCategory = true |
|
label.font = .preferredFont(forTextStyle: .caption1) |
|
label.lineBreakMode = .byTruncatingTail |
|
label.textAlignment = .center |
|
label.textColor = .secondaryLabel |
|
label.numberOfLines = 1 |
|
return label |
|
}() |
|
|
|
override var intrinsicContentSize: CGSize { |
|
return UIView.layoutFittingCompressedSize |
|
} |
|
|
|
override init(frame: CGRect) { |
|
super.init(frame: frame) |
|
|
|
setup() |
|
} |
|
|
|
@available(*, unavailable) |
|
required init?(coder: NSCoder) { |
|
fatalError("init(coder:) has not been implemented") |
|
} |
|
|
|
private func setup() { |
|
|
|
addSubview(titleLabel) |
|
addSubview(subtitleLabel) |
|
|
|
titleLabel.translatesAutoresizingMaskIntoConstraints = false |
|
subtitleLabel.translatesAutoresizingMaskIntoConstraints = false |
|
|
|
NSLayoutConstraint.activate([ |
|
titleLabel.topAnchor.constraint(equalTo: topAnchor), |
|
titleLabel.leadingAnchor.constraint(equalTo: leadingAnchor), |
|
titleLabel.trailingAnchor.constraint(equalTo: trailingAnchor), |
|
subtitleLabel.topAnchor.constraint(equalTo: titleLabel.bottomAnchor), |
|
subtitleLabel.leadingAnchor.constraint(equalTo: titleLabel.leadingAnchor), |
|
subtitleLabel.trailingAnchor.constraint(equalTo: titleLabel.trailingAnchor), |
|
subtitleLabel.bottomAnchor.constraint(equalTo: bottomAnchor) |
|
]) |
|
|
|
} |
|
|
|
} |