I want to align the top position of the items in the red box of picture 2 as shown in picture 1.
When an item is selected, the image is automatically aligned. Is there a way to float the padding from the tab bar based on the top of the image?
You can adjust space of tabBar items using UIEdgeInsets as below:
let items = tabBarCnt.tabBar.items
for item in items!
{
item.imageInsets = UIEdgeInsets(top: 5, left: 0, bottom: -5, right: 0)
}
You can move the position of Image by using this code. If you used title with that image so you should use this title in place of nil.
extension UITabBarController {
override open func viewDidLayoutSubviews() {
let items = tabBar.items
for item in items!
{
if item.title == nil {
item.imageInsets = UIEdgeInsets(top: -20, left: 0, bottom: 10, right: 0)
}
}
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.