ios - 应用程序崩溃,+[SVGKImage imageWithSource :] 中的 *** 断言失败

标签 ios swift image svgkit

我正在 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/

相关文章:

ios - 使用 GPUImage 和 GPUImageHoughTransformLineDetector 检测突出显示的文本边界框

iphone - 定义自定义 iOS 键盘键变体 ~ f/w 4.x+

ios - 在 Swift 中刷新 NSFetchedResultController

javascript - 在 JavaScript 中复制 PHP ImageMagick 的 PaintOpaqueImage 函数

ios - Xcode 8.3 索引和构建速度极慢

ios - 组合框架更新 UI 无法正常工作

swift - 如何启用链接以在 WebView 的默认浏览器中打开

java - 从 Android 项目的 Drawable 中获取图像?

HTML .png 图像作为按钮形状

ios - 处理多个推送通知时出错