iOS 13 UISearchController 书签

标签 ios swift uikit

在 iOS 13 中,我的自定义 UISearchController 书签图像会拉伸(stretch),并且尺寸无法正确调整。

在 iOS 12.x 中,图像非常适合搜索栏:

iOS 12 image

但在 iOS 13 中我得到以下外观:

iOS 13 Image

两个版本中的图像设置方式相同(两个设备上运行的应用程序版本相同)

DispatchQueue.main.async {[weak self] in
    self?.txtSearchBar.setImage(UIImage(named: "barcode_image"), for: .bookmark, state: .normal)
}

我尝试将 searchBar 和所有 subview 的 contentMode 设置为 .scaleAspectFit 但没有成功。我还尝试循环遍历所有 subview 寻找 UIButton 但没有找到它。

最佳答案

事实证明这是由于图像尺寸造成的。

在 iOS 12 中,图像会被调整大小以适应,但在 iOS 13 中情况并非如此。添加适当的 1x、2x 和 3x 尺寸解决了该问题。

关于iOS 13 UISearchController 书签,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58380499/

相关文章:

iphone - 如何截断 UILabel 中字符串中的字符串?

objective-c - 向 iOS 应用程序添加另一个 UIWindow 的优点、问题、示例?

iphone - 如何调整 UIBarButtonItem 的突出显示颜色?

ios - UIButton 不适用于 didSelectAnnotationView

iphone - 刷新 UITabBar 选项卡的 View 或在重新选择选项卡时从 UITabBar 选项卡的 View 调用方法

ios - 在 IOS 中获取错误的运营商名称

ios - 无需重启应用程序即可快速切换应用程序语言

ios - "ipatool failed with an exception: #<CmdSpec::NonZeroExitException:"使用 XCFramwork 归档,启用位码

ios - 将 Swift 集成到导出的 Unity 项目中而不是使用 Objective C?

swift - 在 Realm Swift 中推断查询中的类型而不是字符串谓词?