I have this code that contains the labels and toggles shown in the screenshot below
VStack(alignment: .leading) {
HStack() {
Text("Autostart:")
.font(.custom("SFProText-Medium", size: 12))
Toggle("Launch on Login", isOn: $launchAtLogin).onChange(of: launchAtLogin) { newValue in
LaunchAtLogin.isEnabled = newValue
if !isLoginItem() {
updateUserDefaults(key: "LaunchOnLogin", value: LaunchAtLogin.isEnabled)
}
}.font(.custom("SFProText-Medium", size: 12))
}
.padding(.top, 10)
.padding(.bottom, 10)
HStack() {
Text("Updates:")
.font(.custom("SFProText-Medium", size: 12))
Toggle("Allow Automatic Updates", isOn: $allowAutomaticUpdates).onChange(of: allowAutomaticUpdates) { newValue in
allowAutomaticUpdates = newValue
updateUserDefaults(key: "AllowsAutomaticUpdates", value: allowAutomaticUpdates)
}.font(.custom("SFProText-Medium", size: 12))
}
}
.padding(.top, 10)
.padding(.bottom, 10)
I'm trying to figure out how to get the two toggles to always be vertically aligned. I tried manually setting the frame size of them, as well wrapping them inside of another VStack, but none of that has seemed to work
One way to handle this is to define a custom horizontal alignment guide as follows:
Then use this as the alignment parameter for the outer
VStack
. To align trailing edges of theText
labels within theHStacks
use the modifierPutting this all together…
gives you…