首页 > 解决方案 > 有时在 iOS Swift 上渲染粉色容器的图像资源

问题描述

我在 iOS 手机设备 (Swift) 上看到我的图像资产出现奇怪错误。

错误图像

它应该是什么

所以.. 有时,图像资产被粉红色的容器覆盖。上周之前我没有任何这些错误,不知何故我现在看到了。

图像文件是 png 文件,我将其设置为“渲染为默认”或“渲染为原始图像”。XCode 模拟器上不会发生该错误。

但是,当我将它上传到任何 iOS 设备时,它就会发生。

class EditButton: UIButton {
init() {
    super.init(frame: .zero)
    setImage(UIImage(named: "editPencil"), for: .normal)
    contentMode = .center
    imageView?.contentMode = .scaleAspectFit
    imageView?.isUserInteractionEnabled = true
    clipsToBounds = true
    translatesAutoresizingMaskIntoConstraints = false
    widthAnchor.constraint(equalToConstant: 10).isActive = true
}

required init?(coder: NSCoder) {
    fatalError("init(coder:) has not been implemented")
}

}

有趣的是我在其他 png 文件中没有这些错误..

标签: iosswiftuiimage

解决方案


推荐阅读