Questions tagged [swiftui-tabview]

For questions about TabView - a component in Apple's SwiftUI framework that switches between multiple child views using interactive user interface elements. When using this tag also include the more generic [swiftui] tag where possible.

Filter by
Sorted by
Tagged with
30 votes
3 answers
3k views

OnAppear calls unexpectedly when Keyboard Appears in SwiftUI

I am experiencing very odd behavior in SwiftUI 2.0 and iOS14. When the keyboard appears on the screen, the OnAppear method of other tab's view called automatically. However, this works fine Xcode 11.7 ...
Malav Soni's user avatar
  • 2,808
28 votes
2 answers
9k views

How can I get rid of index dots on TabView with PageTabViewStyle in SwiftUI?

I have the following code but can't seem to remove the dots at the bottom of the TabView. struct ContentView: View { @Environment(\.managedObjectContext) private var viewContext @State ...
alionthego's user avatar
  • 9,179
18 votes
7 answers
17k views

SwiftUI Hide TabView bar inside NavigationLink views

I have a TabView and separate NavigationView stacks for every Tab item. It works well but when I open any NavigationLink the TabView bar is still displayed. I'd like it to disappear whenever I click ...
pawello2222's user avatar
  • 51.3k
17 votes
4 answers
10k views

SwiftUI TabView: how to detect click on a tab?

I would like to run a function each time a tab is tapped. On the code below (by using onTapGesture) when I tap on a new tab, myFunction is called, but the tabview is not changed. struct DetailView: ...
Daniele B's user avatar
  • 20.3k
15 votes
4 answers
6k views

SwiftUI TabView PageTabViewStyle prevent changing tab?

I have a TabView in SwiftUI in the PageViewTabStyle so i can swipe from page to page. I'd like to have a setting that "locks" the current view in place, so the user cannot swipe. Googling ...
Hoopes's user avatar
  • 4,023
11 votes
2 answers
4k views

Add shadow above SwiftUI's TabView

I'm trying to implement TabView in SwiftUI that has the same color as screen background but also has a shadow above it like in this picture: So far I've been able to properly display color, but I don'...
Ella Gogo's user avatar
  • 1,201
11 votes
1 answer
2k views

SwiftUI TabView Updating Selection Does Not Update Selected Tab

For some reason updating the selection does not update the selected tab in this very simple example. My expectation would be that it would show Tab 1 initially, and when I press the Toggle Tab button,...
skajake's user avatar
  • 468
11 votes
2 answers
2k views

SwiftUI - detecting Long Press while keeping TabView swipable

I'm trying to detect a Long Press gesture on TabView that's swipable. The issue is that it disables TabView's swipable behavior at the moment. Applying the gesture on individual VStacks didn't work ...
Kirill's user avatar
  • 819
11 votes
1 answer
1k views

Why is makeUIView being called multiple times when within TabView?

My app has a TabView (PageTabViewStyle) and within each tab is a UIViewRepresentable. I have simplified the code to produce a minimum reproducible example below. The problem is that makeUIView is ...
nicksarno's user avatar
  • 4,085
10 votes
2 answers
7k views

SwiftUI how to keep track of page index in PageTabViewStyle?

I'm trying to keep track of what page the user is on in a TabView that is PageTabViewStyle in SwiftUI but I can't figure out the best way to keep track of the page index? Using .onAppear doesn't work ...
GarySabo's user avatar
  • 6,370
10 votes
1 answer
8k views

SwiftUI onChange() event doesn't work on TabView when swiping

I would like to change the value of a text when the active tab of a TabView changes. I tried using onChange(of: activeTab, perform: {}) to change the value of the state variable that stores the text ...
derivmug's user avatar
  • 203
10 votes
1 answer
7k views

SwiftUI navigation titles within TabView

For the reason outlined in the answer outlined in this question SwiftUI TabView brightness views vertical location the menu structure for my app is NavigationView -> TabView -> sub view with ...
John Sorensen's user avatar
10 votes
1 answer
983 views

SwiftUI: NavigationLink pops out immediately on WatchOS 8.1RC in Tabview

I have discovered a regression in watchOS 8.1RC with NavigationLink triggered from a TabView. It's immediately dismissed. It was working in watchOS 8.0 or in Simulator (watchOS 8.0). Do you know a ...
Raphaël Barthomeuf's user avatar
10 votes
1 answer
2k views

Navigation + Tabview + Sheet broken in iOS 15

It looks like Navigation + TabView + Sheet is broken in iOS 15. When I do this: ContentView -> DetailView -> Bottom Sheet When the bottom sheet comes up, the Detail view is automatically popped ...
skywalkerdude's user avatar
10 votes
0 answers
2k views

How to use TabView or ScrollView for carousel?

I'm trying to create a carousel like some of Apple's apps. The TabView has the paged style but it doesn't "peek" at the previous and next elements. The ScrollView(.horizontal) doesn't snap. ...
TruMan1's user avatar
  • 34.8k
10 votes
1 answer
3k views

iOS14 SwiftUI How to Disable Scroll on TabView [duplicate]

TabView(selection: $vm.selectedTab) { PlanCard_PositiveDay(vm: vm).tag(0) PlanCard_CountdownDay().tag(1) PlanCard_Basalkcal().tag(2) PlanCard_ActivityDiet().tag(3) PlanCard_Schedule()....
wanbo's user avatar
  • 928
9 votes
1 answer
3k views

TabView with PageTabViewStyle() not using available height in ScrollView

so I have a TabView like shown below, but when I try to implement it in a ScrollView I always have to give it a fixed height. Is there a way of telling the tabview to use the space it needs in the ...
Paul's user avatar
  • 183
7 votes
2 answers
2k views

How to update SwiftUI's ForEach in a TabView with PageTabViewStyle modifier when inserting a new element to the collection at first index

This is a very specific issue when using ForEach in a TabView with PageTabViewStyle modifier. Every time I'm inserting an element at the beginning of my array my app crashes. I'm getting a attempt to ...
Marco Boerner's user avatar
6 votes
1 answer
5k views

NavigationStack in combination with a TabView (SwiftUI, iOS16)

What is the correct way to combine the mentioned views. As of now, i have a NavigationStack at the bottom of my app. It displays a LaunchView as root. When a user is authenticated, the main view is ...
Lukas's user avatar
  • 480
6 votes
1 answer
670 views

SwiftUI TabView memory footprint continuously increases when changing page

struct ContentView: View { @State private var selectedIdx = 0 var body: some View { TabView(selection: $selectedIdx) { ForEach(0..<5) { idx in ...
dushandz's user avatar
  • 117
6 votes
1 answer
3k views

How can I adjust the size of an image in a SwiftUI tabItem?

I want to use custom images/icons in my TabView, but when I use a custom image instead of a system image, the image is too large. I've tried to adjust via .frame but it seems to have no effect. I've ...
Nate Thompson's user avatar
5 votes
2 answers
933 views

How can I remove an item from a ForEach inside of a TabView using SwiftUI?

I am having a weird SwiftUI crash that I am not understanding. I have a TabView with a list of 3 images inside of it. I am trying to remove the first image from the list by tapping on the button on ...
Cameron Henige's user avatar
5 votes
1 answer
4k views

Nested TabView - Remove inner tab bar iOS 13, Swift UI

I am using a TabView to represent three tabs. In iOS 14, this is handled nicely, but iOS 13 results in a gray bottom bar which is the tab bar for navigation. How can I remove this bar? Please bear in ...
McGuile's user avatar
  • 818
5 votes
2 answers
2k views

SwiftUI hidesBottomBarWhenPushed equivalent?

I'm trying to hide my TabView when I push a new view in my NavigationView but for now it seems that there is no way to do it (I saw a lot of thing on Internet, but nothing seems work properly for me)? ...
Alexandre Cools's user avatar
5 votes
1 answer
282 views

Toolbar items not hiding / disappearing when TabView selection is changed on macOS

The same code runs perfectly on iOS, and the behaviour is as expected where whenever the tabview selection is changed, the toolbar items are updated accordingly. On macOS, the toolbar items do not ...
Navan Chauhan's user avatar
5 votes
2 answers
5k views

How to Add Space Above TabBar Icons in SwiftUI

I'm working with SwiftUI and made a tab bar that looks like this: The spacing above the icons is pretty minimal, and I'd like to either add some padding to the top of it or increase the height of the ...
Nicolas Gimelli's user avatar
4 votes
1 answer
4k views

Disable Tab View Swipe to Change Page in SwiftUI 2.0

I am using a tab view in my SwiftUI app. I want to disable its swipe to left and write to move to other pages. I checked this answer and also checked this one, but none of them works. They are using ....
Taimoor Arif's user avatar
  • 1,024
4 votes
1 answer
1k views

I created a custom tab bar in SwiftUI, but when I select a tab, it completely reloads the view. How do I prevent this

I created a custom tab bar I am using a switch statement to switch between my views The problem is that the view is being reloaded everytime I switch between tabs How do I "save" the state ...
Ethan Brimhall's user avatar
4 votes
1 answer
795 views

SwiftUI View Switch Statement Causes TabView to Reset

I am using a switch statement in a SwiftUI view: struct OnOffSwitchView: View { @ObservedObject var vm = ViewModel() var body: some View { switch vm.state { case .on: ...
devok's user avatar
  • 362
4 votes
2 answers
2k views

SwiftUI: NavigationView inside TabView height not occupying the fullscreen

I seeing an unexpected UI issue in my SwiftUI project when I add a NavigationView inside a TabView. Here's my code, struct MainView: View { @State private var selectedTab: Int = 0 var body: ...
Karthik's user avatar
  • 91
4 votes
1 answer
1k views

Showing alert from a tab in "More" overflow sends me back to the previous view

I have what should be a simple operation, show an alert in a SwiftUI app that uses a TabView. However, whenever I first show an alert from a tab that was pushed to the "More" overflow screen ...
Tyler V's user avatar
  • 10.5k
4 votes
1 answer
3k views

SwiftUI reload view on double tap on tab item

I'm trying to implement a feature to an app I'm working on so that when a user taps a tab twice, it will automatically send the user back to the tab's initial view. Suppose that I want the following &...
RnadomG's user avatar
  • 155
4 votes
2 answers
665 views

SwiftUI Tab Bar Item Duplicating

This is weird, I have a tab bar with 4 defined tabs and the last item is duplicating itself. TabView { HomeView() .tabItem { Label("Home", systemImage: "chart....
Austin Moca's user avatar
4 votes
3 answers
1k views

`TabView` and `tabViewStyle(.page)` not navigating as expected

I've been experimenting with TabView and tabViewStyle and I've run into a problem with my code I can't figure out. In the code below, when the app opens up on my device I start on the HomeScreen() (as ...
ragavanmonke's user avatar
4 votes
1 answer
1k views

SwiftUI: resetting TabView

I have a TabView with two tabs in a SwiftUI lifecycle app, one of them has complex view structure: NavigationView with a lot of sub-views inside, i.e.: NavigationLinks and their DestinationViews are ...
JAHelia's user avatar
  • 7,500
4 votes
0 answers
109 views

NavigationStack inside paged TabView is broken

I want to have horizontal paging with navigation bars on each page. Going with TabView, there is an issue in combination with page style when nesting NavigationStack. Let me show you an example. The ...
Borut Tomazin's user avatar
4 votes
1 answer
955 views

auto repeat pageview in swiftui

I have a swiftui project. I am using pageview. Normally, when it comes to the last page, it does not scroll further because the pages are finished. What I want is this: the pages continue after ...
ursan526's user avatar
  • 525
4 votes
0 answers
714 views

SwiftUI: showing keyboard in a tab view adds a weird space below second tab view

This sounds a bug in SwiftUI's NavigationView and TabView, when I have a TabView with (let's say) 2 tabs, the first tab has a TextField and the second tab has a NavigationView, follow these steps to ...
JAHelia's user avatar
  • 7,500
4 votes
2 answers
1k views

SwiftUI TabView Content Being Clipped

I am using a TabView with a page style to display scrollable cards that snap into place. I've placed the TabView in a HStack with spacers on each end which centers the TabView. The TabView also has a ...
Nicholas Bastarache's user avatar
3 votes
2 answers
1k views

Custom Tab Bar with variable number of tabs in SwiftUI

I'm trying to replicate the tab bar in the iPad version of Safari, which looks like this: (Is there a third party library which does this? I can't find one) I'm using the code below. Which results in ...
cannyboy's user avatar
  • 24.3k
3 votes
1 answer
2k views

NavigationStack and TabView in Swiftui iOS 16: bug or improper usage?

[Xcode 14.1, iOS 16.1] I have a NavigationStack with a navigationTitle and a TabView with 2 Views. Each View has a ScrollView (see image below): NavigationStack and TabView problem image When I tap on ...
samsamsam's user avatar
3 votes
3 answers
3k views

SwiftUI Matched Geometry Effect not working with multiple ForEach's

I am basically trying to recreate the photos app. In doing so, matched geometry effect should be the best way to recreate the animation that is used in the photos app when you click on an image/close ...
Trevor's user avatar
  • 763
3 votes
1 answer
2k views

SwiftUI Toolbar In a TabBar View

My first view has a NavigationView with a Tab Bar View struct TestView: View { var body: some View { NavigationView { TabTestView() } } } In the Tab Bar, I have ...
bridgenbarbu's user avatar
3 votes
2 answers
1k views

Disable or ignore taps on TabView in swiftui

I have a pretty usual app with a TabView. However, when a particular process is happening in one of the content views, I would like to prevent the user from switching tabs until that process is ...
Hoopes's user avatar
  • 4,023
3 votes
1 answer
447 views

Change Table Background color Swiftui

Hi the swiftui code below shows a table with a title at the top, what I can't do is change the background of the table to gray and align everything at the top, how can I do? below is the current ...
riki's user avatar
  • 1,645
3 votes
1 answer
700 views

How to switch between tabBar and toolbar swiftUI?

In the files App after you pressed the Select button the tabBar switch to the toolbar. How can I do this with swiftUI?(Switch between tabBar and toolbar) struct tabBar: View { var body: some ...
fdvfarzin's user avatar
  • 1,215
3 votes
1 answer
932 views

SwiftUI TabView accentColor(:_) deprecated

I have a tabView and I'm trying to change it's color. Using accentColor(:_) works but it's going to be deprecated. TabView { AppetizerListView() .tabItem { ...
paalma's user avatar
  • 113
3 votes
1 answer
2k views

Disable to Change Page On Swipe of Tab View in SwiftUI

I am using Tab View in my SwiftUI app. I want the changing of page disabled, while swiping left or right. And I had achieved it from this. This works fine but the issue I am facing is I have a button ...
Taimoor Arif's user avatar
  • 1,024
3 votes
1 answer
2k views

Swiftui NavigationView + TabView doesn't show navbar item

I have four Views inside a TabView and each of them contains NavigationView with title. However, when the view first shows up, the navigation view does not show as designed. Even though I have the ...
cc nn's user avatar
  • 115
3 votes
1 answer
533 views

What is 'tag' of tabItem in SwiftUI?

I'm beginner of SwiftUI I recently learning SwiftUI with Youtube Lecture In TabView part, TabView { myView(titleText: "프로필", bgColor: Color.blue) // it's just View I made ...
999rimmy's user avatar

1
2 3 4 5
8