用Cocoapods做過第三方庫的同學應該都知道資源文件(圖片辫封、多語言文件等)要放在bundle里面
podspec資源文件寫法
- 需要打Bundle
s.resources = "Classes/Resources/CTAssetsPickerController.bundle"
s.resources = "你bundle文件的路徑"
- 不需要打Bundle
spec.resource_bundles = { 'CTAssetsPickerController' => ['CTAssetsPickerController/Resources/CTAssetsPicker.xcassets/*/*.png', 'CTAssetsPickerController/Resources/*.lproj'] }
或者
spec.resource_bundles = { 'CTAssetsPickerController' => ['CTAssetsPickerController/Resources/**/*'] }
**/*
這個表示所有文件硝枉,包括文件夾
spec.resource_bundles = { '你的庫名' => ['資源文件路徑/**/*'] }
使用
- 多語言文件
extension String {
var calocale: String {
// 1.創(chuàng)建bundle
// let path = Bundle(for: CTAssetsPickerController.self).path(forResource: "CTAssetsPickerController", ofType: "bundle")!
// 這里for:類名可以隨便,只要是你庫里面的就行倦微。
// 后面.bundle的文件名不能錯
// 2.創(chuàng)建bundle
guard let path = Bundle(for: CTAssetCheckmark.self).path(forResource: "CTAssetsPickerController", ofType: "bundle") else {
return nil
}
let CABundle = Bundle(path: path)
return NSLocalizedString(self, tableName: "CTAssetsPicker", bundle: CABundle, value: "", comment: "")
}
}
- 圖片
private var bundleImage: UIImage? {
guard let path = Bundle(for: CTAssetCheckmark.self).path(forResource: "CTAssetsPickerController", ofType: "bundle") else {
return nil
}
let CABundle = Bundle(path: path)
return UIImage(named: "你要讀取的圖片", in: CABundle, compatibleWith: nil)
}