Reputation: 743
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.
Upvotes: 1
Views: 133
Reputation: 11
if the image is of the system use:
UIImage(systemName: "imageName")?.withRenderingMode(.alwaysTemplate)
Upvotes: 1
Reputation: 258413
Use instead as below
explore.tabBarItem = UITabBarItem(
title: "Explore",
image: UIImage(systemName: "globe")?.withRenderingMode(.alwaysTemplate),
tag: 0
)
Upvotes: 3