我想知道我可以在 tvOS 上的 TextField 中自定义哪些内容。据我所知,我只能使用稍微更改标题和按钮标题SubmitLabel
但是,在查看“设置”界面时,我注意到苹果让它变得更好了一些。它包含描述、标题/描述的不同颜色、按钮的自定义标题,并且当文本字段为空时按钮将被禁用。
所看到的这些事情有可能实现吗?
我尝试使用设计键盘输入体验中的 inputAccessoryView来添加另一个按钮,它可以在 UIKit 上运行,但它不会发送任何点击操作。
所以我的代码现在看起来像这样
import SwiftUI
struct ContentView: View {
@State private var text = ""
var body: some View {
TextField("TitleKey", text: $text)
.submitLabel(.continue)
}
}
Run Code Online (Sandbox Code Playgroud)
我不知道如何进一步自定义此视图。
小智 0
在 Apple TV 的 SwiftUI 中,SecureField有TextField一个限制,即它只接受简单文本作为标签。以下是 SecureField 的文档:
public struct SecureField<Label> : View where Label : View {
Run Code Online (Sandbox Code Playgroud)
要提供更详细的标签或说明,实用的解决方法是在条目上方使用单独的Text视图。例如:SecureField
struct ContentView: View {
@State private var text = ""
var body: some View {
VStack(spacing: 16) {
Text("Apple ID Password")
.font(.title3)
Text("Enter the password for \"asda\".")
.foregroundStyle(.secondary)
.padding(.bottom, 100) // Arbitrary number, might be better to size it with spacing
SecureField(text: $text) {
Text("Password")
}
.submitLabel(.continue)
.frame(width: 600) // Arbitrary number, might be better to size it with spacing
}
}
}
Run Code Online (Sandbox Code Playgroud)
这种方法使用额外的Text上下文视图,具有可定制的间距和布局,有效地解决了SecureField标签限制。
| 归档时间: |
|
| 查看次数: |
202 次 |
| 最近记录: |