答案 0 :(得分:0)
夫特:
//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")
答案 1 :(得分:0)
在swift 4.2
中与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)
}