Skip to content

Instantly share code, notes, and snippets.

@genedelisa
Last active November 12, 2016 11:46
Show Gist options
  • Save genedelisa/5449857113707934d65bf46bf1d2c312 to your computer and use it in GitHub Desktop.
Save genedelisa/5449857113707934d65bf46bf1d2c312 to your computer and use it in GitHub Desktop.
UIToolbar with bar buttons using a custom font using Swift 3
if let nav = navigationController {
nav.setToolbarHidden(false, animated: false)
// doesn't really set the button's tint
UIToolbar.appearance().tintColor = UIColor.black
// instead of setting the text color of each bar button
UIBarButtonItem.appearance().tintColor = UIColor.black
//http://www.fileformat.info/info/unicode/char/26ed/index.htm
let settingsButton = UIBarButtonItem(title: "\u{2699}",
style: .plain,
target: self,
action: #selector(TracksViewController.settings))
// set the font for all bar buttons along with the foreground color
if let font = UIFont(name: "Helvetica", size: 22) {
UIBarButtonItem.appearance().setTitleTextAttributes(
[NSFontAttributeName: font,
NSForegroundColorAttributeName:UIColor.black // will override toolbar tint
],
for: UIControlState.normal)
// to set just an individual button
// settingsButton.setTitleTextAttributes([NSFontAttributeName: font], for: UIControlState.normal)
}
// or to get the default font and size
//let font = UIFont.systemFont(ofSize: UIFont.labelFontSize)
let peace = UIBarButtonItem(title: "\u{262E}",
style: .plain,
target: self,
action: #selector(TracksViewController.settings))
// from the musical symbol block looks good
let eighth = UIBarButtonItem(title: "\u{1D160}",
style: .plain,
target: self,
action: #selector(TracksViewController.settings))
toolbarItems = [settingsButton,peace, eighth]
// or
self.navigationItem.setRightBarButtonItems([settingsButton, peace, eighth], animated: true)
self.navigationItem.setLeftBarButtonItems([settingsButton, peace, eighth], animated: true)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment