gpt4 book ai didi

ios - 如何居中 TabBarItem - Swift

转载 作者:行者123 更新时间:2023-11-29 05:16:53 38 4
gpt4 key购买 nike

如何将 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 居中,或者如何计算该图标的位置?

最佳答案

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

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/

38 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com