iOS7,UISearchBar的backgroundImage [英] iOS7, backgroundImage for UISearchBar

查看:322
本文介绍了iOS7,UISearchBar的backgroundImage的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在iOS 6和iOS 7之间进行UI的转换。

I'm making the transition of the UI between iOS 6 and iOS 7.

我们有一个与UISearchDisplayController相关的UISearchBar,我设置了它的backgroundImage navigationBar和searchBar为使用颜色动态创建的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是一种半透明的灰色。当我按下取消时,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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆