SFSymbolsPicker 是一个简单而强大的 SwiftUI 选择器,它允许你在 iOS 和 macOS 应用中轻松选择 Apple 的 SF Symbols,并提供简易的绑定!
该软件包加载 SF Symbols 的方式已经发生了根本性的改变。现在,这些符号在运行时直接由系统读取,因此用户可以在更新设备后立即访问 Apple 添加的最新符号。特别感谢 mackoj 提出的实施此解决方案的建议。
这是一个简短的用法示例。你可以在 UsageExample.swift 中找到完整的代码。
@State private var icon = "star.fill"
@State private var isPresented = false
var body: some View {
NavigationView {
VStack {
Button("Select a symbol") {
isPresented.toggle()
}
Image(systemName: icon).font(.title3)
.sheet(isPresented: $isPresented, content: {
SymbolsPicker(selection: $icon, title: "Pick a symbol", autoDismiss: true)
}).padding()
}
.navigationTitle("SF Symbols Picker")
}
}
使用自定义按钮
...
.sheet(isPresented: $isPresented, content: {
SymbolsPicker(selection: $icon, title: "Pick a symbol", autoDismiss: true) {
// Your custom view...
// For example:
Text("Close!")
}
}).padding()
...
要求
在 Xcode 中,转到 File -> Add Package Dependencies...
并粘贴仓库的 URL:https://github.com/alessiorubicini/SFSymbolsPicker
。然后选择主分支或所需的版本。
版权所有 2024 (©) Alessio Rubicini。
此仓库的许可证为 MIT 许可证。
请参阅 LICENSE 文件以获取完整参考