gpt4 book ai didi

ios - Swift UIImage 命名返回 nil 并在 Assets 中使用通用图像

转载 作者:行者123 更新时间:2023-11-30 13:04:30 27 4
gpt4 key购买 nike

我有一个 iPhone 应用程序 (iOS/Swift) Xcode 项目。我有一个名为 map_pin_icon.svg 的图像保存到我的桌面上(来自 wikicommons @ https://commons.wikimedia.org/wiki/File:Map_pin_icon.svg )。

我将其拖放到 Xcode 项目的 Assets.xcassets 文件夹中,它显示在列表中。当我单击列表中的map_pin_icon(应用程序图标集下方)时,它说图像集具有任何/任何尺寸的通用图像,但它显示的图标是空白文件图标,而不是图像文件中的图标。如果我选择通用图像并按空格键,它会在“快速 View ”窗口中显示正确的图标。

在 ViewController.swift 中,我在 viewDidLoad() 中:

    let theImage = UIImage(named: "map_pin_icon.svg")
if(theImage == nil) {
print("NIL IS NOT ALLOWED")
} else {
print("\(theImage)")
}
let theImageView = UIImageView(image: theImage)

果然,当我运行模拟器(iPhone 4s 上的 iOS 8.0,这是我所需的最低兼容性设备)时,我得到以下输出日志:

    NIL IS NOT ALLOWED

我哪里出错了?提前致谢。

最佳答案

iOS 本身并不将 SVG 图像描绘为 UIImage 的基础。如果没有一些第三方库,您将无法使用此图像。

关于ios - Swift UIImage 命名返回 nil 并在 Assets 中使用通用图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39553074/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com