在 iOS 13 中,我的自定义 UISearchController 书签图像会拉伸(stretch),并且尺寸无法正确调整。
在 iOS 12.x 中,图像非常适合搜索栏:
但在 iOS 13 中我得到以下外观:
两个版本中的图像设置方式相同(两个设备上运行的应用程序版本相同)
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/