I created a simple TabBarController and put system images as icons:
class TabBarController: UITabBarController {
private let profile = ProfileView()
private let explore = ExploreView()
override func viewDidLoad() {
super.viewDidLoad()
configure()
}
private func configure() {
explore.tabBarItem = UITabBarItem(
title: "Explore",
image: UIImage(named: "globe")?.withRenderingMode(.alwaysOriginal),
tag: 0
)
profile.tabBarItem = UITabBarItem(
title: "Profile",
image: UIImage(named: "person.fill")?.withRenderingMode(.alwaysOriginal),
tag: 1
)
self.viewControllers = [explore, profile]
self.selectedIndex = 0
}
}
But when I run the project, I see only titles without icons. What's a problem? Other questions I found were storyboard oriented but how to fix it programmatically.
if the image is of the system use:
UIImage(systemName: "imageName")?.withRenderingMode(.alwaysTemplate)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.