A simple and configurable "dropdown" view built for UINavigationItem.titleView
.
Just add DropdownTitleView
to your Podfile and pod install. Done!
pod 'DropdownTitleView'
Create an instance of DropdownTitleView
, configure it, and set it as a UINavigationItem
's titleView
:
func viewDidLoad() {
super.viewDidLoad()
let titleView = DropdownTitleView()
titleView.configure(title: "Hello world!", subtitle: "Is this thing on?")
navigationItem.titleView = titleView
}
Add touch handling like you would any other UIControl
:
func viewDidLoad() {
super.viewDidLoad()
// setup and set titleView
titleView.addTarget(
self,
action: #selector(onTitle),
for: .touchUpInside
)
}
@objc func onTitle() {
print("do something")
}
DropdownTitleView
has several appearance options:
titleFont
andtitleColor
-UIFont
andUIColor
of the top title labelsubtitleFont
andsubtitleColor
-UIFont
andUIColor
of the bottom subtitle labelchevronTintColor
-UIColor
tint of the chevron image
All of these values are configurable via UIAppearance
as well!
DropdownTitleView.appearance().chevronTintColor = .blue
DropdownTitleView.appearance().titleColor = .black
DropdownTitleView.appearance().subtitleColor = .lightGray
DropdownTitleView.appearance().titleFont = .systemFontOfSize(18)
DropdownTitleView.appearance().subtitleFont = .systemFontOfSize(13)
You can also control the features of the view with params in configure(...)
function:
subtitle
- Leavenil
to remove the subtitle and vertically center the titlechevronEnabled
- Set tofalse
to remove the chevronaccessibilityLabel
andaccessibilityHint
- Set Accessibility features on the control
- Created with ❤️ by Ryan Nystrom