SwiftUI HStack vetrical Alignment doesn't work?
You should align the outer HStack
instead.
Also the inner one is useless. So you can get rid of it.
VStack{
Spacer()
HStack(alignment: .top) {
Text("Error: \(errorText)")
Spacer()
Button("x"){ self.errorText = "" }
}
.frame(minHeight:10)
.padding(.all, 5)
}
SwiftUI: Spacer doesn't work at ScrollView
Use GeometryReader
A container view that defines its content as a function of its own size and coordinate space.
https://developer.apple.com/documentation/swiftui/geometryreader
GeometryReader { geometry in
ScrollView {
VStack() {
-----
}
.frame(width: geometry.size.width, height: geometry.size.height)
}
}
Doing so, the VStack is full-screen.
You may not neeed to use ScrollView
, because you do not need to scroll to see its content.
var body: some View {
VStack() {
Text("Title_1")
.padding(.bottom, 35.0)
Text("Title_2")
.padding(.bottom, 32.0)
Text("Title_3")
.padding(.bottom, 27.0)
Spacer()
Button(action: { print("ACTION") }) {
Text("OK")
.font(.title)
.fontWeight(.semibold)
.foregroundColor(Color.red)
}
.frame(height: 35)
.cornerRadius(8.0)
.padding(.bottom, 25.0)
}
.frame(maxWidth: .infinity)
}
But if your content's height is more than the screen height, the OK
button is at the bottom, regardless. Hence, you do not need to do anything.
Related Topics
Swiftui Hstack with Equal Height
How to Record My MAC's Internal Sound, Not the Microphone!, Using Avcapturesession
Ckcontainer.Discoverallidentities Always Fails
Swift Objc_Getassociatedobject Always Nil
Swiftui: Using View Modifiers Between Different iOS Versions Without #Available
Swift: Hashable Struct with Dictionary Property
Swift Safely Unwrapping Optinal Strings and Ints
Scenekit Won't Scale a Dynamic Body
Updating Fetchedresultscontroller for Predicate Set by Uisearchbar
How to Hash a String to Sha512 in Swift
Nstableview Inside Nspopover Looks Different as Standalone
Xcode 8 Shell Script Invocation Error