如何将 TabBarIcon 放置在中间?它应该放置在这个红色圆圈的顶部。
我的红圈代码:
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 居中,或者如何计算该图标的位置?
最佳答案
您可以尝试使用UITabBarItem
的imageInsets
,如下代码:
let items = tabBarCnt.tabBar.items
for item in items!
{
item.imageInsets = UIEdgeInsets(top: 5, left: 0, bottom: -5, right: 0)
}
关于ios - 如何居中 TabBarItem - Swift,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59097409/