我想将标签栏项目的图像设置得更大。所以我把这个代码放在我的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)
但是如果我在一个项目上点击两次或更多次,则te图像变得越来越大。 我想我仍然无法正确使用EdgeInsets。 如何解决缩放问题并为图像设置更大的尺寸? 我根据Apple文档创建了图像文件(75px / 3x,50px / 2x,25px / 1x)。