ios - 如何居中 TabBarItem - Swift

标签 ios swift xcode tabbar

如何将 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/

相关文章:

ios - 即使我使用 iOS 10、Xcode 8 在 info.plist 中添加了 NSCameraUsageDescription,应用程序也会崩溃

ios - 如何快速访问底 View

c++ - basic_regex 是一个 undefined symbol - Boost 框架链接器错误

ios - 可执行文件在 Xcode 中使用无效权利进行签名

ios - 应用商店 : transferring an iOS app and app ID

iphone - 变换表格 View

ios - App 中的非公开 API,__strlcat_chk,__strlcpy_chk

swift - 尝试在 View Controller 和 TableView Controller 之间传递数据时应用程序崩溃

swift - Firebase 查询找不到电子邮件地址?

ios - 确定基于网格的游戏中可能的移动/路径