iOS中Cocoapods的Bundle
2017-02-16 本文已影响0人
xiAo__Ju
用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.创建bundle
// let path = Bundle(for: CTAssetsPickerController.self).path(forResource: "CTAssetsPickerController", ofType: "bundle")!
// 这里for:类名可以随便,只要是你库里面的就行。
// 后面.bundle的文件名不能错
// 2.创建bundle
let path = Bundle(for: CTAssetCheckmark.self).resourcePath! + "/CTAssetsPickerController.bundle"
let CABundle = Bundle(path: path)!
return NSLocalizedString(self, tableName: "CTAssetsPicker", bundle: CABundle, value: "", comment: "")
}
}
- 图片
private var bundleImage: UIImage? {
let path = Bundle(for: CTAssetCheckmark.self).resourcePath! + "/CTAssetsPickerController.bundle"
let CABundle = Bundle(path: path)!
return UIImage(named: "你要读取的图片", in: CABundle, compatibleWith: nil)
}