我想将标签栏项目的图像设置为更大的尺寸。所以我把这段代码放在我的 TabBarViewController.viewDidLoad() 中:
let titleTabrItems = ["Favourites","Calc","Time","Live","Shop"]
for (index,item) in (self.tabBar.items ?? []).enumerated() {
item.title = ""
let image = item.image?.withRenderingMode(UIImageRenderingMode.alwaysOriginal)
let selectedImage = item.selectedImage?.withRenderingMode(UIImageRenderingMode.alwaysOriginal)
item.image = image
if index < titleTabrItems.count {
item.title = titleTabrItems[index]
}
item.titlePositionAdjustment = UIOffsetMake(0, 10000)
item.selectedImage = selectedImage
item.imageInsets = UIEdgeInsets(top: 0, left: -10, bottom: -6, right: -10)
}
self.navigationController?.setNavigationBarHidden(true, animated: false)
但是如果我在一个项目上单击两次或更多次,则图像会变得越来越大。我想我仍然无法正确使用 EdgeInsets。如何解决缩放问题并为图像设置更大的尺寸?我根据 Apple 文档(75px/3x、50px/2x、25px/1x)创建了图像文件。