I am trying to set a selection image to UITabbar item,
Here is the screenshot.
It works fine on all other screens except iPhoneX
How can i make it appear from y = 0
I am trying to set a selection image to UITabbar item,
Here is the screenshot.
It works fine on all other screens except iPhoneX
How can i make it appear from y = 0
Note:
Use selectionIndicatorImage property to specify a custom selection image. Your image is rendered on top of the tab bar but behind the contents of the tab bar item itself. The default value of this property is nil, which causes the tab bar to apply a default highlight to the selected item
If you are using selectionIndicatorImage for certain purpose put this code in TabBarController class
, here i have use viewDidLayoutSubviews
because of getting dynamic height of tabbar in both landscape and portrait mode.
override func viewDidLayoutSubviews() {
super.viewDidLayoutSubviews()
print("current height \(tabBar.frame.size.height)")
let selTab = UIImage(named: "tab1.png")
let numberOfTabs: CGFloat = 2.0
let tabSize = CGSize(width: (self.view.frame.width)/numberOfTabs, height: tabBar.frame.size.height)
UIGraphicsBeginImageContext(tabSize);
selTab?.draw(in: CGRect(x: 0, y: 0, width: tabSize.width, height: tabSize.height))
let reSizeImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
tabBar.selectionIndicatorImage = reSizeImage
}