ios-13-将 UIColor 设置为 BackgroundImage 时应用程序崩溃
ios-13-App crashes when setting UIColor as BackgroundImage
我正在尝试用 UIColor
设置 searchbar
背景图片。我的代码在 ios 12.x 中运行良好,但在 ios 13 中崩溃。我的代码如下。
[[UISearchBar appearance] setScopeBarBackgroundImage:[UIImage imageWithCGImage:(__bridge CGImageRef)([UIColor clearColor])]];
崩溃日志显示 由于未捕获的异常 'NSInternalInconsistencyException' 正在终止应用程序,原因:'imageRef passed is not a CGImageRef'
谁能提出解决崩溃的替代方法?
在您的代码中,您将 UIColor 对象转换为 CGImageRef。这没有意义,我不知道为什么它会在 iOS 12.
中起作用
您可能只想制作一个填充纯色的 UIImage。是这样的:
https://gist.github.com/uknowho/5915365
我正在尝试用 UIColor
设置 searchbar
背景图片。我的代码在 ios 12.x 中运行良好,但在 ios 13 中崩溃。我的代码如下。
[[UISearchBar appearance] setScopeBarBackgroundImage:[UIImage imageWithCGImage:(__bridge CGImageRef)([UIColor clearColor])]];
崩溃日志显示 由于未捕获的异常 'NSInternalInconsistencyException' 正在终止应用程序,原因:'imageRef passed is not a CGImageRef'
谁能提出解决崩溃的替代方法?
在您的代码中,您将 UIColor 对象转换为 CGImageRef。这没有意义,我不知道为什么它会在 iOS 12.
中起作用您可能只想制作一个填充纯色的 UIImage。是这样的: https://gist.github.com/uknowho/5915365