There are two solutions I have seen can be used to change the colour of the title bar in SwiftUI:
Making the use of NavigationView
Ignoring the sage area with .ignoresSafeArea()
I have no use for a NavigationView nor I want to use .ignoresSafeArea() since it helps on giving the TabView bottom tab space.
The only requirement to the solution I am looking for is that it cannot be for iOS 16 and above only, since it will not be viable to use in production for at least the next two years.
TL;DR:
I need to change the colour of the title bar (the upper-most part of the app) with features available in versions prior to iOS 16, and without the use of NavigationView and .ignoresSafeArea()
The white stuff in this image:
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 a two-tabbed tab view and in the second tab there are different pages being displayed. There is a navigationview and navigationlink within some of the pages. The navigation bar has a weird grey background that I can’t make go away. Any ideas how to remove that?
So it turns out I had a .padding around the view for the second tab, so everything within that view was padded, which introduced this. Removing that solved the issue.
I followed Apple's guide on using UIPageViewController with SwiftUI. Their guide works fine. However I ran into an issue, where if I have my PageView inside a ScrollView - the height of the PageView is no longer respected and I have to set the frame manually. Not ideal, as the content inside PageView is dynamic and thus, heights will vary.
This seems to be an issue with ScrollView; as I have another view - UIViewRepresentable - that is a simple wrapper around WKWebView - with the same issue.
Is there a way to have these views size themselves, inside a SwiftUI ScrollView?
If I place these views outside of a ScrollView and into a simple VStack for example, they size themselves correctly.
I'm stumble on two problems. I'm trying to cnstruct a view which will contain elements placed on full display of the watch (from top to bottom, full-screen). Some watch apps has such views.
Code below shows how to move content to the top+left edge of the display. And there are two problems.
var body: some View {
ZStack(alignment: .topTrailing) {
Rectangle().foregroundColor(Color.green)
HStack(spacing: 0) {
VStack(alignment: .trailing, spacing: 0) {
Text("Hello World")
.padding(.trailing, 20)
Text("Hello World")
Text("Hello World")
}
}
}.edgesIgnoringSafeArea(.all)
.navigationBarHidden(true)
}
As you can see, element Text aligned to the top+trailing with little padding.
By default on the top of display Navigation Bar with Timer are displayed. Modificator '.navigationBarHidden(true)' working and properly hides Navigation Bar, but not a Timer. This is the first problem.
I can't post the image yet.
Second problem: Two warnings are displaying in console while running the app on simulator. And i'm not sure of its meanings. Despite of the warnings simulator is is not crushed.
WatchKit Extension libMobileGestalt utility.c:421: no value found for key 1129072723
WatchKit Extension [default] has no material, defaulting to light aluminum.
My appretiations in advance.
For your first problem, you cannot remove the time from the navigation bar. The primary focus for the AW is to tell time, therefore it should always be visible. The only occasions when the time is not visible is when dictating or writing something using the swipe 'keyboard'.
Warnings are not necessarily a problem, you can ignore these (especially the second one)