iOS7, backgroundImage for UISearchBar(iOS7,UISearchBar 的 backgroundImage)
问题描述
我正在 iOS 6 和 iOS 7 之间转换 UI.
I'm making the transition of the UI between iOS 6 and iOS 7.
我们有一个与 UISearchDisplayController 相关的 UISearchBar,我已将 navigationBar 和 searchBar 的 backgroundImage 设置为使用颜色动态创建的 1x1 图像.
We have a UISearchBar related to a UISearchDisplayController, I have set the backgroundImage of the navigationBar and the searchBar to a 1x1 image dynamically created with a color.
self.searchDisplayController.searchBar.translucent = NO;
self.searchDisplayController.searchBar.barTintColor = [UIColor clearColor];
self.searchDisplayController.searchBar.tintColor = [UIColor myTintColor];
self.searchDisplayController.searchBar.backgroundImage = [self imageWithColor:[UIColor myBGColor]];
self.searchDisplayController.searchBar.scopeBarBackgroundImage = [self imageWithColor:[UIColor myBGColor]];
在 iOS6 上,一切正常.在 iOS7 上,当 searchBar 被选中时,scopeBar 出现了很好的 backgroundImage(用 searchBar.scopeBarBackgroundImage 设置)但是 searchBar 是一种半透明的灰色.当我按下 Cancel 时,searchBar backgroundImage 又回来了.
On iOS6, everything works as expected. On iOS7, when the searchBar is selected, the scopeBar appears with the good backgroundImage (set with searchBar.scopeBarBackgroundImage) but the searchBar is a kind of translucent gray. When I press on Cancel, the searchBar backgroundImage is back.
////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////
编辑问题
////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////
实际上,我确实在这里和那里使用了 barTintColor 和其他选项,但它不起作用.这就是 barTintColor 设置为相同颜色的结果.但是上面有这个白色层
Actually, I did use the barTintColor and other options here and there but it doesn't work. That is the result with the barTintColor set with the same color. But there is this white layer on top
推荐答案
在 iOS 7 中,属性 backgroundImage 和 scopeBarBackgroundImage 不再按预期工作并变为半透明.
In iOS 7, the properties backgroundImage and scopeBarBackgroundImage no longer work as expected and become translucent.
iOS 7 中引入了以下方法来解决此问题.(文档 这里)
The following method has been introduced in iOS 7 which addresses this problem. (Docs here)
setBackgroundImage:forBarPosition:barMetrics:
这是你应该做的:
[self.searchDisplayController.searchBar setBackgroundImage:[self imageWithColor:[UIColor yourColor]]
forBarPosition:0
barMetrics:UIBarMetricsDefault];
这里,barPosition : 0 是 UIBarPositionAny.
Swift 代码:
self.searchDisplayController.searchBar.setBackgroundImage(self.image(color: UIColor.yourColor), for: UIBarPosition(rawValue: 0)!, barMetrics:.default)
这篇关于iOS7,UISearchBar 的 backgroundImage的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:iOS7,UISearchBar 的 backgroundImage
基础教程推荐
- 如何从 logcat 中删除旧数据? 2022-01-01
- AdMob 广告未在模拟器中显示 2022-01-01
- Android:getLastKnownLocation(LocationManager.NETWORK_PROVIDER 2022-01-01
- 通过重定向链接在 Google Play 中打开应用 2022-01-01
- navigator.geolocation.getCurrentPosition 在 Android 浏览器上 2022-01-01
- libGDX 从精灵或纹理中获取像素颜色 2022-01-01
- iOS4 创建后台定时器 2022-01-01
- Cocos2d iPhone 非矩形精灵触摸检测 2022-01-01
- NSString intValue 不能用于检索电话号码 2022-01-01
- iPhone - 获取给定地点/时区的当前日期和时间并将其与同一地点的另一个日期/时间进行比较的正确方法 2022-01-01
