Auto-update Lucide Icons

用于 Swift Package Manager 的 Lucide 图标

此仓库集成了 Lucide 图标,并通过 Swift Package Manager (SPM) 提供使用。通过此软件包,您可以轻松地在 macOS 和 iOS 应用程序中使用 Lucide 图标。

安装指南

要使用 Swift Package Manager 安装此软件包,请按照以下步骤操作

  1. 打开您的 Xcode 项目。
  2. 在项目导航器中选择您的项目。
  3. 选择 Package Dependencies 选项卡(软件包依赖项)。
  4. 单击 + 按钮以添加新的软件包依赖项。
  5. 输入此仓库的 URL:https://github.com/yourusername/lucide-icons-swift.git。(请将 `yourusername` 替换为实际的用户名)
  6. 选择您想要使用的版本,然后单击 Add Package(添加软件包)。

使用方法

安装软件包后,您可以开始在项目中使用 Lucide 图标。

导入软件包

在您的 Swift 文件中,导入软件包

import LucideIcons

iOS 中的使用方法

对于 iOS,UIImage 扩展提供了一个便捷的初始化器,可以直接从模块的 bundle 中通过 Lucide ID 加载图像

import UIKit

let image: UIImage = Lucide.tada

if let icon: UIImage? = .init(lucideId: "tada") {
    // Use your icon
}

macOS 中的使用方法

对于 macOS,NSImage 扩展提供了一个静态函数,可以从模块的 bundle 中通过 Lucide ID 获取图像

import AppKit

let image: NSImage = Lucide.tada

if let icon = NSImage.image(lucideId: "yourIconId") {
    // Use your icon
}

SwiftUI 中的使用方法

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 图标愉快!