此仓库集成了 Lucide 图标,并通过 Swift Package Manager (SPM) 提供使用。通过此软件包,您可以轻松地在 macOS 和 iOS 应用程序中使用 Lucide 图标。
要使用 Swift Package Manager 安装此软件包,请按照以下步骤操作
Package Dependencies
选项卡(软件包依赖项)。+
按钮以添加新的软件包依赖项。https://github.com/yourusername/lucide-icons-swift.git
。(请将 `yourusername` 替换为实际的用户名)Add Package
(添加软件包)。安装软件包后,您可以开始在项目中使用 Lucide 图标。
在您的 Swift 文件中,导入软件包
import LucideIcons
对于 iOS,UIImage
扩展提供了一个便捷的初始化器,可以直接从模块的 bundle 中通过 Lucide ID 加载图像
import UIKit
let image: UIImage = Lucide.tada
if let icon: UIImage? = .init(lucideId: "tada") {
// Use your icon
}
对于 macOS,NSImage
扩展提供了一个静态函数,可以从模块的 bundle 中通过 Lucide ID 获取图像
import AppKit
let image: NSImage = Lucide.tada
if let icon = NSImage.image(lucideId: "yourIconId") {
// Use your icon
}
import SwiftUI
import LucideIcons
struct ContentView: View {
var body: some View {
VStack {
Image(nsImage: Lucide.tada) // For macOS
Image(uiImage: Lucide.tada) // For iOS
Text("Hello, Lucide Icons!")
}
}
}
struct ContentView: View {
var body: some View {
#if canImport(UIKit)
if let uiImage = UIImage(lucideId: "tada") {
Image(uiImage: uiImage)
}
#elseif canImport(AppKit)
if let nsImage = NSImage.image(lucideId: "tada") {
Image(nsImage: nsImage)
}
#endif
}
}
您可以在 lucide.dev/icons 查看所有可用的图标。
祝您在 Swift 项目中使用 Lucide 图标愉快!