Skip to content

Instantly share code, notes, and snippets.

@aakhedr
Last active April 25, 2018 08:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aakhedr/a485e008ee2202ae741bb5cfddb77674 to your computer and use it in GitHub Desktop.
Save aakhedr/a485e008ee2202ae741bb5cfddb77674 to your computer and use it in GitHub Desktop.
Appearance Proxies
func appearances() {
let windows = UIApplication.shared.windows
for window in windows {
for view in window.subviews {
view.removeFromSuperview()
window.addSubview(view)
}
}
setupProxies()
}
func setupProxies() {
/// 1. Navigation Bars
UINavigationBar.appearance().titleTextAttributes = [
NSAttributedStringKey.font: Fonts.sharedFonts.navBarTitleFont
]
if #available(iOS 11.0, *) {
UINavigationBar.appearance().largeTitleTextAttributes = [
NSAttributedStringKey.font : Fonts.sharedFonts.navBarLargeTitleFont
]
}
/// 2. Search Bars
// A. Search Bar Text Field
(UITextField.appearance(whenContainedInInstancesOf: [UISearchBar.self])).defaultTextAttributes = [
NSAttributedStringKey.font.rawValue : Fonts.sharedFonts.segmentedControlFont
] as [String : Any]
// B. Search Bar Scope Buttons
UISearchBar.appearance().setScopeBarButtonTitleTextAttributes([
NSAttributedStringKey.font.rawValue : Fonts.sharedFonts.segmentedControlFont
]
, for: .normal)
/// 3. Bar Buttons Items
UIBarButtonItem.appearance().setTitleTextAttributes([
NSAttributedStringKey.font: Fonts.sharedFonts.navBarTitleFont
]
, for: .normal)
/// 4. Segmented Controls
UISegmentedControl.appearance().setTitleTextAttributes([
NSAttributedStringKey.font : Fonts.sharedFonts.segmentedControlFont
]
, for: .normal)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment