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.
365
questions
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
...
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 ...
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 ...
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: ...
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 ...
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'...
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,...
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 ...
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 ...
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 ...
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 ...
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 ...
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 ...
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 ...
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. ...
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()....
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 ...
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 ...
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 ...
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
...
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 ...
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 ...
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 ...
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)?
...
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 ...
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 ...
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
....
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 ...
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:
...
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: ...
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 ...
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 &...
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....
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 ...
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 ...
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 ...
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 ...
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 ...
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 ...
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 ...
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 ...
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 ...
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 ...
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 ...
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 ...
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 ...
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 {
...
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 ...
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 ...
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
...