最新消息:20210917 已从crifan.com换到crifan.org

【未解决】swift初始化一个空的UIImage

Swift crifan 2721浏览 0评论

尝试了:

var headerImage:UIImage = UIImage(named: "")!

编译通过了,但是运行时出错:

fatal error: unexpectedly found nil while unwrapping an Optional value

发现有个:

UIImage(imageLiteral: String>)

要去搞清楚什么含义。

搜:

swift UIImage imageLiteral

参考:

UIKit Changes for Swift

Added UIImage.init(imageLiteral: String)
extension UIImage : _ImageLiteralConvertible {
    required convenience init(imageLiteral name: String)
}
extension UIImage {
    func stretchableImageWithLeftCapWidth(_ leftCapWidth: Int, topCapHeight topCapHeight: Int) -> UIImage
    var leftCapWidth: Int { get }
    var topCapHeight: Int { get }
}
extension UIImage : _ImageLiteralConvertible {
    required convenience init(imageLiteral name: String)
}

iOS知识小集 第六期(2015.10.20) – 南峰子的技术博客

UIImage的带参数imageLiteral的,最新的官网的文档中也没有解释:

+ imageWithContentsOfFile: – UIImage Class Reference

估计是:

最新的named的参数的之前的写法。

所以暂时不管了。

搜:

swift UIImage init empty

参考:

How to declare an empty UIImage variable in swift – Quora

也是这么写的:“ var imgg:UIImage = UIImage(named: "")!”

难道可以工作???

ios – UIImage on swift can’t check for nil – Stack Overflow

【总结】

算了,暂时不去弄个空的UIImage了。

就还是:

    var headerImage:UIImage?

算了吧。

转载请注明:在路上 » 【未解决】swift初始化一个空的UIImage

发表我的评论
取消评论

表情

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址

网友最新评论 (1)

  1. = UIImage(),不谢
    Yves5年前 (2018-11-22)回复
97 queries in 0.189 seconds, using 23.41MB memory