3

当我使用 SwiftUI 展示一张工作表时,所有内容都会变粗。如果我轻扫一下,粗体就会消失。

例子:

.navigationBarItems(leading:
    Button(action:{
      self.isSheetPresented.toggle()
    }) {
      Text("Display")
    }
    .frame(width: 25, height: 45)
    .sheet(isPresented: $isSheetPresented) {
      Textfield("Hello", text: $binding)
    })
  }

除了申请之外,有没有简单的解决方法

.fontWeight(.regular) or .font(.body) 

对一切?

PS:在 MacOS 11.0 Beta (20A5395g) 上运行 Xcode Version 12.2 beta 3 (12B5035g)

4

2 回答 2

7

尝试将工作表移出 navigationBarItems 并附加到正文内的某个视图,例如

// ... other views
.navigationBarItems(leading:
    Button(action:{
      self.isSheetPresented.toggle()
    }) {
      Text("Display")
    }
    .frame(width: 25, height: 45)
)

...

} // end of NavigationView
.sheet(isPresented: $isSheetPresented) {    // << here !!
  Textfield("Hello", text: $binding)
}
于 2020-10-16T15:46:59.153 回答
0

好的,我做了一些测试:

.navigationBarItems(leading:
                                Button(action: {self.showingSettings = true}) {
                Image(systemName: "gear")
            }
            //.sheet(isPresented: $showingAddItem, content: {
              //  AddView(expirations: self.expirations)
            ,
                    trailing:
                        Button(action: {self.showingAddItem = true}) {
                Image(systemName: "plus")
            }
            //.sheet(isPresented: $showingSettings, content: {
            //    SettingsView()
            
        )
        .sheet(isPresented: $showingAddItem, content: {
            AddView(expirations: self.expirations)
        })
        .sheet(isPresented: $showingSettings, content: {
            SettingsView()
        })

但是通过这样做,尾随按钮不起作用,只有前导按钮

于 2021-02-19T11:55:40.643 回答