Skip to content

Instantly share code, notes, and snippets.

View ioskevinshah's full-sized avatar

Kevin Shah ioskevinshah

View GitHub Profile
var lblSubTitle: UILabel = {
var lbl: UILabel = UILabel()
lbl.translatesAutoresizingMaskIntoConstraints = false
lbl.backgroundColor = .clear
lbl.textAlignment = .center
lbl.adjustsFontSizeToFitWidth = true
lbl.minimumScaleFactor = 0.75
lbl.textColor = .darkGray
lbl.font = .systemFont(ofSize: UIFont.smallSystemFontSize)
return lbl
fileprivate var verticalStackView: UIStackView = {
let stackView: UIStackView = UIStackView()
stackView.translatesAutoresizingMaskIntoConstraints = false
stackView.isUserInteractionEnabled = false
stackView.alignment = .center
stackView.axis = .vertical
stackView.distribution = .equalCentering
return stackView
}()
override init(frame: CGRect) {
super.init(frame: frame)
/// Preparing UIView
prepareUIView()
}
fileprivate func addSubView() {
verticalStackView.addArrangedSubview(lblTitle)
verticalStackView.addArrangedSubview(lblSubTitle)
addSubview(verticalStackView)
}
fileprivate func prepareConstraintForHorizontalStackView() {
verticalStackView.centerXAnchor.constraint(equalTo: centerXAnchor).isActive = true
verticalStackView.centerYAnchor.constraint(equalTo: centerYAnchor).isActive = true
verticalStackView.widthAnchor.constraint(equalTo: widthAnchor, multiplier: 1).isActive = true
verticalStackView.heightAnchor.constraint(equalTo: heightAnchor, multiplier: 1).isActive = true
}
fileprivate func prepareUIView() {
/// Adding SubView(s)
addSubView()
/// Preparing constraint(s)
prepareConstraintForHorizontalStackView()
}
// MARK: - Configuartion Related Method(s)
extension NavigationTitleDropDownButton {
func configure(_ title: String, subTitle: String? = nil) {
lblTitle.text = title
lblSubTitle.text = subTitle
lblSubTitle.isHidden = (subTitle?.isEmpty == true)
}
}
/// Variable Declaration(s)
var navigationButtonView: NavigationTitleDropDownButton = NavigationTitleDropDownButton()
func prepareNavigationBar() {
navigationButtonView.addTarget(self, action: #selector(handleNavigationTitleSelection(_:)), for: .touchUpInside)
navigationButtonView.configure("Kevin Shah", subTitle: "iOS Developer")
navigationItem.titleView = navigationButtonView
}