Search code examples
iosxcodeswiftios9tabbar

Selected TabBar item height


I am making an app with a tabbar inside a UITabBarController.

I want to make the selected item a different (custom) color and a little higher than the rest of the items.

I set the background of the tabbar to a custom color using a background image:

UITabBar.appearance().backgroundImage = UIImage(named: "TabBarBlue")
UITabBar.appearance().tintColor = UIColor.whiteColor()

I have searched online, but I couldn't find a good solution, anyone here knows how to achieve this?


Solution

  • Solved this by simply setting the frame height 15 points higher:

    let numberOfItems = CGFloat(tabBar.items!.count)
    let tabBarItemSize = CGSize(width: tabBar.frame.width / numberOfItems, height: tabBar.frame.height + 15)
    tabBar.selectionIndicatorImage = UIImage.imageWithColor(UIColor(netHex:0xe00628), size: tabBarItemSize).resizableImageWithCapInsets(UIEdgeInsetsZero)