我正在 swift 项目中使用 SVGKit。我按照以下步骤将 SVGKit Framework 和第 3 方资源文件夹正确导入到我的项目中 ( https://github.com/SVGKit/SVGKit )。
我在项目内创建了一个包含 .svg 图像集的文件夹,我使用以下代码将图像加载到 testIcon(ImageView) 中。
let lockImage: SVGKImage = SVGKImage(named: "LockIcon.svg")
let lockImageLocal: UIImage = lockImage.uiImage
testIcon.image = lockImageLocal
但是我收到以下错误,
** Assertion failure in +[SVGKImage imageWithSource:], /Users/fss/Downloads/SVGKit- 2.x/Source/SVGKImage.m:229
*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Invalid parameter not satisfying: newSource != nil'
请告诉我如何将 .svg
图像(在我的项目内部)的路径提及到 SVGKImage 图像类或如何解决此问题。
最佳答案
请从图像名称中删除 .svg
。此方法named:
不需要扩展。
或者你也可以尝试这种方式...
swift 4
if let imagePath = Bundle.main.path(forResource: "imageName", ofType: "svg")
{
let lockImage: SVGKImage = SVGKImage(contentsOfFile: imagePath)
let lockImageLocal: UIImage = lockImage.uiImage
testIcon.image = lockImageLocal
}
Obj-c类型
NSString *imagePath = [NSBundle mainBundle][ pathForResource:@"imageName" ofType:@"svg"];
UIImage *image = [UIImage imageWithContentsOfFile:imagePath];
关于ios - 应用程序崩溃,+[SVGKImage imageWithSource :] 中的 *** 断言失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48880502/