I'm trying to change the background of a TabBarItem or to make a whole Image which take all the space.
Like the example below :
Do You have an Idea how to do that in swift
I'm trying to change the background of a TabBarItem or to make a whole Image which take all the space.
Like the example below :
Do You have an Idea how to do that in swift
Swift:
//change icon and title color
UITabBar.appearance().tintColor = UIColor.redColor()
//change background default color
UITabBar.appearance().barTintColor = UIColor.blackColor()
//change selected background image
UITabBar.appearance().selectionIndicatorImage = UIImage(named: "tabSelected")
in swift 4.2
with iOS 12.1
func setUpSelectionIndicatorImage(withColors colors: [UIColor]) {
//Make selection indicator image from color and set it to tabbar
let singleTabWidth: CGFloat = self.tabBar.frame.size.width / CGFloat(self.tabBar.items?.count ?? 1)
let height = DeviceType.IS_IPHONE_X ? 55 : self.tabBar.frame.size.height
let singleTabSize = CGSize(width:singleTabWidth , height: height)
let edgeInsets = DeviceType.IS_IPHONE_X ? UIEdgeInsets(top: 1, left: 0, bottom: 0, right: 0) : .zero
self.tabBar.selectionIndicatorImage = UIImage.gradient(size: singleTabSize, colors: colors)?.resizableImage(withCapInsets: edgeInsets)
}
override func viewDidLayoutSubviews() {
let colors = [UIColor.white, UIColor.green]
setUpSelectionIndicatorImage(withColors: colors)
}