I want to change the default font used in SwiftUI to Ariel.
Far as I can tell its embedded
I know I can set like
Text("Hello, world!").font(.custom(
"AmericanTypewriter", fixedSize: 36))
but I have to do this on every label and loose the automatic size stuff like
.font(.title)
Is there a way to set the system font globally
Related
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)
}
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:
I'm curious what SwiftUI is doing under the covers when applying an idealHeight to a Spacer's frame. Will the Spacer use the idealHeight as its target height but adjust accordingly based on the room available? It seems to work for my use case but wasn't sure if this is best practice or not.
VStack {
SomeCustomView()
Spacer()
.frame(idealHeight: 100)
AnotherCustomView()
}
For an iOS 14 widget I want to fix the font size in the widget, even when a user has its settings to bigger type in accessibility settings (larger type). I want this because the text is already very big (big digital clock widget), and if it is even bigger the text falls of the widget and therefore is not legible. I am using a custom font.
I tried to fix the font size with .font(.custom("MyCustomFont", size: 17)). But even then the type is rendered bigger depending on user settings. How can I permanently fix font size in a iOS 14 widget? Is there a workaround or another method to fix font size for the widget?
You can use .environment(\.sizeCategory, .large) to enforce the size category. Here is an example:
var body: some View {
VStack {
Text("text1")
Text("text2")
}
.environment(\.sizeCategory, .large)
}
The default category is large but here you can find more categories.
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)