问题描述
我正在尝试在选项卡栏的选项卡上显示图像,但无法看到图像。 代码:
@objc func didTapButton() {
let tabBarVC = UITabBarController()
let firstGameRoomController = FirstGameRoomController()
let secondGameRoomController = SecondGameRoomController()
let thirdGameRoomController = ThirdGameRoomController()
tabBarVC.setViewControllers([firstGameRoomController,secondGameRoomController,thirdGameRoomController],animated: true)
let items = tabBarVC.tabBar.items
items![0].image = resizeImage(image:UIImage(named: "c_1")!,newWidth:24);
items![1].image = resizeImage(image:UIImage(named: "c_2")!,newWidth:24);
items![2].image = resizeImage(image:UIImage(named: "c_3")!,newWidth:24);
tabBarVC.modalPresentationStyle = .fullScreen
present (tabBarVC,animated: true)
}
func resizeImage(image: UIImage,newWidth: CGFloat) -> UIImage {
let scale = newWidth / image.size.width
let newHeight = image.size.height * scale
UIGraphicsBeginImageContext(CGSize(width: newWidth,height: newHeight))
image.draw(in: CGRect(x: 0,y: 0,width: newWidth,height: newHeight))
let newImage = UIGraphicsGetimageFromCurrentimageContext()
UIGraphicsEndImageContext()
return newImage!
}
class FirstGameRoomController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
view.backgroundColor = .red
title = "Game Room 1"
}
}
你能告诉我上面的代码有什么问题吗?我尝试过调整图像大小和不调整图像大小。请看截图
-阿伦
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)