【问题标题】:How to use RoundedBorderTextFieldStyle in SwiftUI for TextField after API change in Xcode 11 Beta 5?在 Xcode 11 Beta 5 中的 API 更改后,如何在 SwiftUI 中为 TextField 使用 RoundedBorderTextFieldStyle?
【发布时间】:2019-12-10 13:14:48
【问题描述】:

在 Xcode 11 Beta 5 之前。我使用这种语法在我的 TextField 之外放置一个圆形边框:

TextField("Expression", text: $expression)
      .textFieldStyle(.roundedBorder)

遗憾的是,这种方法已被弃用,现在给我警告。

新方法应该是:roundedBorder' 已弃用:直接使用RoundedBorderTextFieldStyle

但我不知道如何使用它。

从开发者文档中我可以看出。 RoundedBorderTextFieldStyle 符合 TextFieldStyle 协议。

而且 TextField 似乎有 RoundedBorderTextFieldStyle 作为嵌套结构?(不确定我是否理解正确,RoundedBorderTextFieldStyle 写在开发者文档中 TextField 下方)

我不知道如何使用新的 RoundedBorderTextFieldStyle。

我正在寻找在 Beta 5 中编写以下代码的正确方法:

    TextField("Placeholder", text: $texts)
        .textFieldStyle(.roundedBorder)

【问题讨论】:

    标签: xcode textfield swiftui beta


    【解决方案1】:

    你说:

     .textFieldStyle(RoundedBorderTextFieldStyle())
    

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-01-01
    • 1970-01-01
    • 2022-11-15
    相关资源
    最近更新 更多