2

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 :

Tabbar

Do You have an Idea how to do that in swift

Community
  • 1
  • 1
Stranger B.
  • 7,456
  • 21
  • 60
  • 101

2 Answers2

0

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")
Terence
  • 423
  • 2
  • 13
0

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)
}
Ketan Sodvadiya
  • 354
  • 3
  • 10