简体   繁体   中英

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?

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.

This bug is solved in iOS 16 beta.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM