Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SwiftUI custom TabBar Icons

Tags:

swift

tabbar

this is about SwiftUI.

my custom PNG 75x75, Black, Background Transparent TabBar icons doesn't get the color. My Icons are always black, no matter if there active or not. What I'm doing wrong?

Text("Test")
   .tabItem {
       Image("MyIcon")
       Text("MyName")
   }.tag(0)
like image 508
Maximilian Gravemeyer Avatar asked Dec 06 '19 14:12

Maximilian Gravemeyer


People also ask

How to create a tab bar in SwiftUI using Xcode?

Assuming you’ve created a SwiftUI project using Xcode 12, let’s start with a simple text view like this: To embed this text view in a tab bar, all you need to do is wrap it with the TabView component and set the tab item description by attaching the .tabItem modifier like this: This will create a tab bar with a single tab item.

What is tabview in SwiftUI?

A tab bar appears at the bottom of an app screen and let users quickly switch between different functions of an app. In UIKit, you use the UITabBarController to create the tab bar interface. For the SwiftUI framework, it provides a UI component called TabView for developers to display tabs in the apps.

How to create a custom tab button in customtabbarview?

First we need to create our enum with the images and names for Tab Bar icons. The images that I will use will be from SF Symbols After this we need to build our Tab Button inside CustomTabBarView, but first we need to define tow variables, one for our current tab bar and another for matched geometry effect.

How to place the whole plus tab bar icon above the screen?

To ensure that the whole plus tab bar icon is placed slightly above the tab view, we apply the .offset modifier to our ZStack. Our ZStack should be shifted upwards by half the height of the tab bar. Since our tab view is one-eight as high as the screen, we write:


1 Answers

The template mode should work here, like

Image("MyIcon")
    .renderingMode(.template)
like image 124
Asperi Avatar answered Sep 20 '22 14:09

Asperi