【问题标题】:ios-13-App crashes when setting UIColor as BackgroundImage将 UIColor 设置为 BackgroundImage 时 ios-13-App 崩溃
【发布时间】:2020-01-26 16:47:12
【问题描述】:

我正在尝试用UIColor 设置searchbar 背景图像。我的代码在 ios 12.x 中运行良好,但在 ios 13 中崩溃。我的代码如下。

[[UISearchBar appearance] setScopeBarBackgroundImage:[UIImage imageWithCGImage:(__bridge CGImageRef)([UIColor clearColor])]];

崩溃日志显示由于未捕获的异常“NSInternalInconsistencyException”而终止应用程序,原因:“通过的 imageRef 不是 CGImageRef”

谁能提出解决崩溃的替代方法?

【问题讨论】:

  • 令人惊讶的是,在 iOS 13 之前没有给您带来麻烦...这:(__bridge CGImageRef)([UIColor clearColor]) 确实 返回 CGImage / CGImageRef

标签: ios objective-c uiimage uisearchbar


【解决方案1】:

在您的代码中,您将 UIColor 对象转换为 CGImageRef。这没有意义,我不知道为什么它会在 iOS 12 中起作用。

您可能只想制作一个用纯色填充的 UIImage。像这样的东西: https://gist.github.com/uknowho/5915365

【讨论】:

    猜你喜欢
    • 2023-03-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-10-02
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多