'SwiftUI toolbar text size changes on appear
Related to this
I am trying to make an app based on Notes app.
I set my iPhone text size to the smallest, and when the view changes, the texts on new view's toolbar gets bigger.
Code :
.toolbar {
ToolbarItem(placement: .navigationBarTrailing) {
HStack {
Button {
parentList.starred.toggle()
} label: {
Label("Toggle Favorite", systemImage: parentList.starred ? "star.fill" : "star")
.labelStyle(.iconOnly)
.foregroundColor(parentList.starred ? .yellow : .gray)
}
Button(action: editList) {
Label("Edit List", systemImage: "ellipsis.circle")
}
EditButton()
}
}
ToolbarItem(placement: .bottomBar) {
Spacer()
}
ToolbarItem(placement: .status) {
if parentList.childvocabularies!.count == nil {
Text("")
.foregroundColor(.secondary)
.font(.caption)
}
else if parentList.childvocabularies!.count == 1{
Text("\(parentList.childvocabularies!.count) Vocabulary")
.foregroundColor(.secondary)
.font(.caption)
} else {
Text("\(parentList.childvocabularies!.count) Vocabularies")
.foregroundColor(.secondary)
.font(.caption)
}
}
ToolbarItem(placement: .bottomBar) {
Button(action: addItem) {
Label("Add Item", systemImage: "plus")
}
}
}
Is this a bug?
Solution 1:[1]
UINavigationBar.setAnimationsEnabled(false)
Adding this to view's init disables all animations. I know it's not a proper solution but it may help troubleshoot.
Solution 2:[2]
While this introduces other issues (like changing left padding), you can try:
Text("ACCOUNT")
.font(.boldFont(size: 14))
.minimumScaleFactor(0.5)
.fixedSize(horizontal: true, vertical: false)
Minimum scale factor prevents the font size from increasing and fixed size prevents the text from being truncated. Bold font is our custom extension getting our custom font in bold.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Steven J. Selcuk |
| Solution 2 | DharmanBot |

