LoginSignup
2
1

More than 3 years have passed since last update.

Swift:自作CocoaPodsライブラリでAssets Catalogを使う

Last updated at Posted at 2019-12-09

1.自作フレームワーク内に.xcassetsファイルを作成
2.普通にリソースを加える
3.Assets Catalogからリソースを取得

画像を取得する例
public func bundleImage(name: String) -> NSImage? {
    // ↓ライブラリのデモTarget用
    var bundle = Bundle(identifier: "ライブラリTargetのBundle Identifier")
    // ↓ライブラリをimportした時用
    if bundle == nil {
        bundle = Bundle(for: このメソッドがあるクラス名.self)
    }
    return bundle?.image(forResource: NSImage.Name(name))
}

4..podspecにリソースを使うことを書き加える

.podspec
spec.resources = "ライブラリ名/**/*.xcassets"

↑ライブラリ名と言うのはつまりプロジェクトのルートフォルダのことを指します。

参考

How to use images asset catalog in cocoapod library for iOS

2
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
1