SwiftUI的模态文字全部大写吗?

时间:2020-10-26 19:06:13

标签: ios swiftui

在SwiftUI模态视图中,出于某种原因,文本为ALL CAPS,直到与之交互,然后所有文本均捕捉到所需状态(正常情况下)。造成这种行为的原因是什么?

ListIngredientHeader只是表单中Section中的标题。然后,该视图位于视图层次结构最顶部的NavigationView内。

// NOTE: Presents the modal view below
struct ListIngredientHeader: View {
    @Binding var ingredients: [MeasuredIngredient]
    @State var showIngredientsModal: Bool = false
    var body: some View {
        HStack {
            Image(uiImage: "?".image()).resizable().frame(width: 25, height: 25)
            Text("Ingredients").font(.headline)
            Spacer()
            Button {
                self.showIngredientsModal = true
            } label: {
                Image(systemName: "plus.circle").resizable().foregroundColor(.blue).frame(width: 25, height: 25)
            }
            .sheet(isPresented: self.$showIngredientsModal) {
                ModalIngredientView(ingredients: $ingredients)
            }
        }
    }
}


// MARK: Modal views
struct ModalIngredientView: View {
    @Environment(\.presentationMode) var presentationMode
    @Binding var ingredients: [MeasuredIngredient]
    @State private var ingredientString: String = ""
    @State private var measurementSelection = FoodUnit.deciliters
    @State private var measurementQuantity: String = ""
    @State private var measurementType: MeasurementType = .volume
    @State private var quantityNotApplicable: Bool = false
    var body: some View {
        NavigationView {
            Form {
                HStack {
                    Text("Name")
                    TextField("Potato", text: $ingredientString)
                }
                
                HStack {
                    Text("Quantity").foregroundColor(quantityNotApplicable ? .gray : .primary)
                    TextField(quantityNotApplicable ? "-" : "100", text: $measurementQuantity).keyboardType(.numberPad).disabled(quantityNotApplicable)
                    Divider()
                    Toggle("N.A", isOn: $quantityNotApplicable)
                }
                
                Picker("Measurement", selection: $measurementSelection) {
                    ForEach(FoodUnit.allCases) {
                        Text("\($0.rawValue)").tag($0)
                    }
                }
            }
            .navigationBarTitle("New Ingredient")
        }
    }
}

Prior to touch

After touching

0 个答案:

没有答案