I am using TabView in my SwiftUI app. I used the side Preview as I was building it. The bottom tab shows on all device types in the Preview section but when I build it to either a real device or simulate device, the TabView doesn't show at all.
Previews are for each individual view. They don't represent the whole app.
You'll need to set it as the root view inside YourAppName_App.swift.
#main
struct YourAppNameApp: App {
var body: some Scene {
WindowGroup {
YourTabBarView() /// replace with the name of your tab bar view
}
}
}
Related
What I am trying to build
Apple Watch app(written in SwiftUI, targeting watchOS 7 or higher, built with Xcode 14.1)
The Problem
Picker placed inside a ScrollView on an apple watch device does not work as expected
I want to find out how to get the Picker to work as expected, stated below.
Expected behavior
On an iOS simulator, a Picker inside a ScrollView works as expected.
If I try scroll interaction on the Picker area, the ScrollView part doesn’t get scrolled and only the Picker gets scrolled.
whereas on the watch simulator Example,
If I try to scroll the Picker by touching the Picker area, the whole ScrollView reacts and moves up and down. And I am not able to control the Picker properly.
The code I wrote is as follows:
ScrollView {
//..other view elements..
Picker(selection: $currentDay) {
ForEach(weekDays, id: \.self) {
Text($0)
}
} label: {
Text("")
}
.frame(width: 148,height: 50)
.pickerStyle(.wheel)
//..other view elements..
}//: ScrollView
Things I have tried
putting the Picker inside a VStack/ZStack/HStack
giving the Picker fixed frame values / giving other elements inside the ScrollView fixed frame values
Is there a good way to hide the up down arrows in the picker default style. I am using ios 16. It seems that the older version does not have such arrows.
Also, is there a setting to set the picker's background to the same style as the datepicker in the image without manually setting the background and radious?
I have been struggling on this small feature and tried googling for a few hours but no luck. Any idea will be appreciated
The suggested Menu solution works well if you only have a few options. The problem I've experienced with the Menu solution is that if there are very many options the Menu doesn't automatically scroll to the currently selected option the way the Picker does.
The solution I've used is to use ZStack to place an opaque picker on top of a custom view (my "label"). Setting the opacity modifier on the Picker to 0.025 makes it invisible on your device but it will still trigger when you tap it.
This way you get all the native functionality of the Picker (including scrolling to the selected option) and you can make the label look any way you want without having to create your own custom picker.
Here's the code:
ZStack {
// Custom picker label
Text("\(value)")
.font(.title)
.foregroundColor(.blue)
.styleDataEntry(colorScheme: colorScheme) // a custom formatter View extension
// Invisible picker
Picker("", selection: $value) {
ForEach(0 ..< 200) { option in
Text("\(option)").tag(option)
}
}
.pickerStyle(.menu)
.opacity(0.025)
}
I have started learning swiftUI so I have question about Navigation View. My app starts with splash screen which is embedded in Navigation View and after that I have navigation link to the second screen which is Tab View. Do I need navigation views in child views of Tab View if I have some button etc and I also need to go to other screens from them or I use primary navigation view which tab view is embedded in?
When using both TabView and NavigationView, TabView should always be the parent view and should contain NavigationView inside it.
Hope this clarifies what you’re looking for?
What is the name of the SwiftUI View shown in the image (the side popup view on the top right of the screen)? If it's custom made, then what default SwiftUI view do I use to achieve this look in my own app?
For example, if the device is in dark mode and I set the color scheme to light with the code below, the status bar is invisible because it's still white and won't get updated until I do something like bring up the keyboard or trigger an action sheet.
struct ContentView: View {
var body: some View {
Text("Hello, world!")
.preferredColorScheme(.light)
}
}
This somehow works on my iPad but not on my iPhone or any of the simulators. And I couldn't find a way to change the status bar style with the SwiftUI App life cycle.
Am I missing something here? Does anyone have a solution for this?
Screenshot of status bar not visible
Try using environment modifier instead
.environment(\.colorScheme, .light)