SwiftUI-不带标题的操作表,Alert.Button使用视图而不是文本

有什么办法可以使操作表中没有标题部分? SwiftUI代码中的“动作表”定义如下:

public struct actionSheet {
   /// Creates an action sheet with the provided buttons.
   public init(title: Text,message: Text? = nil,buttons: [actionSheet.Button] = [.cancel()])
   /// A button representing an operation of an action sheet presentation.
   public typealias Button = Alert.Button
}

由于标题仅符合Text,所以我认为也许仅添加Text(“”)即可完成工作;但是,这将使标题的空间为空,而不是将其删除。用nil代替Text(“”)也不起作用。

此外,有什么方法可以使操作表的按钮具有视图,如下所示:

struct actionItem: View {

  var body: some View {

    HStack {

        Image(systemName: "phone")

        Spacer()

        Text("Call 1-408-123-4567")
    }
  }
}
a434637464 回答:SwiftUI-不带标题的操作表,Alert.Button使用视图而不是文本

简短的回答是“否”。 SwiftUI的当前实现将始终为标题留出空间,并且仅对其按钮采用Text视图。

目前尚不清楚这是否是因为Apple在今年发布SwiftUI之前才花了很多时间,并且想解决最简单和最常见的用例,还是因为他们采取了原则原则,即ActionSheets应该始终具有标准外观,包括标题和仅文本按钮。我们将不得不拭目以待。

本文链接:https://www.f2er.com/3155911.html

大家都在问