Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/107.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Objective c 使用UISearchBar时使其余视图变为灰色_Objective C_Ios_Xcode_Uisearchbar - Fatal编程技术网

Objective c 使用UISearchBar时使其余视图变为灰色

Objective c 使用UISearchBar时使其余视图变为灰色,objective-c,ios,xcode,uisearchbar,Objective C,Ios,Xcode,Uisearchbar,我想模仿使用UISearchBar的标准UI,现在我开始搜索时,试图将视图的其余部分设置为灰色,我尝试将视图的背景色设置为灰色,但我正在使用UITableView中的部分,它们没有变为灰色。有人有什么理由吗 使用标准的UISearchController满足您的tableview搜索需求。您没有看到部分标题变为灰色的原因是它们绘制在灰色背景之上,并且不透明;换句话说,他们的alpha为1 如果您正在寻找获得所需效果的建议,我的第一个反应是添加一个覆盖UIView作为要“灰显”的区域的子视图,并在

我想模仿使用UISearchBar的标准UI,现在我开始搜索时,试图将视图的其余部分设置为灰色,我尝试将视图的背景色设置为灰色,但我正在使用UITableView中的部分,它们没有变为灰色。有人有什么理由吗


使用标准的
UISearchController
满足您的tableview搜索需求。

您没有看到部分标题变为灰色的原因是它们绘制在灰色背景之上,并且不透明;换句话说,他们的
alpha
为1

如果您正在寻找获得所需效果的建议,我的第一个反应是添加一个覆盖
UIView
作为要“灰显”的区域的子视图,并在某些事件发生时更改其背景色。大概是这样的:

// You have to choose what view is the one that needs to be grayed out.
// I'll call the view you want to gray out "viewToBeGrayed"

UIView *grayOverlay = [[UIView alloc] initWithFrame:viewToBeGrayed.frame];

// Initially, the overlay should be clear
[grayOverlay setBackgroundColor:[UIColor clearColor]];

[viewToBeGrayed addSubview:grayOverlay];
然后,当您想“灰显”视图以显示时,只需将
grayOverlay
的背景色更改为某个半透明的灰色值:

[grayOverlay setBackgroundColor:[UIColor colorWithWhite:0.5 alpha:0.5]];
最后,如果要消除“灰显”效果,只需将视图设置回“清除”:

[grayOverlay setBackgroundColor:[UIColor clearColor]];

这应该是一个很好的起点。如果需要任何其他帮助,请发表评论。

可能会添加灰色(RGBA 0.5)覆盖视图?该链接不再相关。请更新或删除您的答案。问题本身不再相关。但当然,我会更新我的答案,以反映出您无论如何都不应该再尝试这种方法,因为新的UISearchController API是标准的。同样,公认的答案清楚地解释了如何实现这一目标。但谢谢你3年后提醒我@tannery你说得对。如果我让你不高兴,我很抱歉,但我努力不让链接断开。感谢您改进您的答案-现在它对新用户更有用。