I just recently started working on the beginning “Your First iOS and SwiftUI App” video.
I’ve been playing around with specific “Modifiers” one of which is for changing font size.
Just using a Text View I’m able to alter the font size by using .font(.largeType).
This works every time for any font size that I choose.
I’ve tried to apply this same modifier to the title in an Alert View. Swift lets me add this modifier
but it doesn’t allow the text size to change accordingly. So, what am I doing wrong or is it because the Alert View is limited in size and can’t be modified.
Thanks for your help.
Gary
Here’s my code :
import SwiftUI
struct ContentView: View { @State private var showAlert: Bool = false
var body: some View {
VStack {
Text(“My First App!”) .font(.largeType)
.fontWeight(.semibold)
.foregroundColor(.green)
.padding(50)
Button(action: {
print(“Hit Me!”)
self.showAlert = true
}) {
Text("Hit Me!")
.padding()
}
.alert(isPresented: $showAlert) {
() -> Alert in
return Alert (title:Text("Hello World!")
, message: Text("This is my first pop-up.")
**.font(.largeType)**
, dismissButton: .default(Text("Super!")))
}
}
}
Thanks for your reply. I’m now convinced that that’s true.
For views that can’t be altered, it seems like you should get an error message explaining why you can’t apply these modifiers. Instead, SwiftIU lets you apply modifiers to these types of "unchangeable " views as if they would work.
If you want to create it yourself as a totally custom thing, create a new div element in your DOM (as the last child of the body, and give it the maximum z-index you can or you use), position that absolute (top:0,left:0), and write there HTML whatever you want. With some JS you can position it to center of the screen/layout.
@elearner ,
You cannot modify them via swiftUI, UIKit developers would try to subclass or extend the classes to change/modify the font sizes. However it is advised to leave it to system default as it will adapt based on the user settings.