目录
目录README.md

TokenField

A SwiftUI wrapper for NSTokenField

struct MyToken {
    var title: String
}

struct TestView: View {
    @State var tokens: [MyToken]
    var body: some View {
        VStack {
            TokenField($tokens, { $0.title })
        }
    }
}

TokenField takes a Binding to a RandomAccessCollection of elements to use as its tokens. When the token type does not conform to StringProtocol, it also requires a closure to convert tokens to a String.

struct TestIdentifiableStringsView: View {
    @State var tokens: [String]
    var body: some View {
        VStack {
            TokenField($tokens)
        }
    }
}

FormTokenField can be used within a Form view and be given a label that will align with standard Form labels.

struct TestFormsView: View {
    @State var tokens: [MyToken]
    @State var strings: [String]
    var body: some View {
        Form {
            FormTokenField(title:"Tokens", $tokens, { $0.title })
            FormTokenField({ Text("Tokens") }, $strings)
        }
    }
}
关于
39.0 KB
邀请码
    Gitlink(确实开源)
  • 加入我们
  • 官网邮箱:gitlink@ccf.org.cn
  • QQ群
  • QQ群
  • 公众号
  • 公众号

©Copyright 2023 CCF 开源发展委员会
Powered by Trustie& IntelliDE 京ICP备13000930号