0
我programicaly加載故事板成的UITabBarController,但由於某種原因UITabBarItem不加載圖像或selectedImage所有除了第一個標籤不加載編程方式創建的UITabBarController子視圖不加載UITabBarItem圖像
但是,如果你點擊其他選項卡圖標負荷
故事板加載實例
import UIKit
class ProfileViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
let defaultImag = UIImage(named: "Profile")?.withRenderingMode(.alwaysOriginal)
let selectedImag = UIImage(named: "Profile_selected")?.withRenderingMode(.alwaysOriginal)
self.tabBarItem = UITabBarItem(title: nil, image: defaultImag, selectedImage: selectedImag)
self.tabBarItem.imageInsets = UIEdgeInsets(top: 10, left: 0, bottom: -10, right: 0);
}
}
的UITabBarController
import UIKit
class TabBarViewController: UITabBarController {
override func viewDidLoad() {
super.viewDidLoad()
}
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
let discoverStoryboard = UIStoryboard(name: "Discover", bundle: nil)
let discoverViewController = discoverStoryboard.instantiateInitialViewController()! as UIViewController
let favouritesStoryboard = UIStoryboard(name: "Favourites", bundle: nil)
let favouritesViewController = favouritesStoryboard.instantiateInitialViewController()! as! FavouritesViewController
let profileStoryboard = UIStoryboard(name: "Profile", bundle: nil)
let profileViewController = profileStoryboard.instantiateInitialViewController()! as UIViewController
self.viewControllers = [discoverViewController, favouritesViewController, profileViewController]
}
}
圖像不加載? –
我添加了屏幕截圖 –