如何将TabBarItem居中-Swift

问题描述 投票:0回答:1

如何将我的TabBarIcon放置在中间?它应该放在这个红色圆圈的顶部。 Screenshot

我的红圈代码:

let numberOfItems = CGFloat(tabBar.items!.count)
let tabBarItemSize = CGSize(width: tabBar.frame.width / numberOfItems, height: tabBar.frame.height)
let itemBackgroundView = UIView(frame: CGRect(x: tabBarItemSize.width / 2, y: 35, width: 6, height: 6))
itemBackgroundView.backgroundColor = .red
itemBackgroundView.layer.cornerRadius = 3
tabBar.addSubview(itemBackgroundView)

如何将我的TabBarIcon居中,或者如何计算该图标的位置?

ios swift xcode tabbar
1个回答
0
投票

您可以尝试使用imageInsetsUITabBarItem,如下代码:

let items = tabBarCnt.tabBar.items
for item in items!
{
   item.imageInsets = UIEdgeInsets(top: 5, left: 0, bottom: -5, right: 0)
}
© www.soinside.com 2019 - 2024. All rights reserved.