Skip to content

Instantly share code, notes, and snippets.

@mishimay
Created December 17, 2021 05:54
Show Gist options
  • Save mishimay/32f966c631334edf364133bf8ed3904e to your computer and use it in GitHub Desktop.
Save mishimay/32f966c631334edf364133bf8ed3904e to your computer and use it in GitHub Desktop.
let appearance = UITabBarAppearance()
appearance.configureWithTransparentBackground()
appearance.backgroundColor = backgroundColor
appearance.backgroundImage = backgroundImage
[appearance.stackedLayoutAppearance,
appearance.compactInlineLayoutAppearance,
appearance.inlineLayoutAppearance]
.forEach {
$0.selected.iconColor = selectedColor
$0.selected.titleTextAttributes[.foregroundColor] = selectedColor
$0.normal.iconColor = unselectedColor
$0.normal.titleTextAttributes[.foregroundColor] = unselectedColor
// Tab bar title text workaround
// https://stackoverflow.com/questions/58641202/ios-tabbar-item-title-issue-in-ios13
if let font = $0.normal.titleTextAttributes[.font] as? UIFont {
$0.normal.titleTextAttributes[.font] = UIFont.systemFont(ofSize: font.pointSize)
}
}
tabBar.standardAppearance = appearance
tabBar.scrollEdgeAppearance = appearance
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment