gpt4 book ai didi

objective-c - 使用 UISearchBar 时使 View 的其余部分变灰

转载 作者:塔克拉玛干 更新时间:2023-11-02 09:04:13 25 4
gpt4 key购买 nike

我想模仿使用 UISearchBar 的标准 UI,现在我试图在开始搜索时将 View 的其余部分设为灰色,我尝试通过设置背景颜色来做到这一点 View 变为灰色,但我在 UITableView 中使用部分,它们没有变灰。有人知道这是为什么吗?

UITableView when using searchbar

最佳答案

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

如果您正在寻找获得所需效果的建议,我的第一 react 是添加一个叠加层 UIView 作为您希望“变灰”的区域的 subview ,并在某些事件发生时更改其背景颜色。像这样:

// 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];

然后,当您想要“变灰”viewToBeGrayed 时,只需将 grayOverlay 的背景色更改为一些半透明的灰度值即可:

[grayOverlay setBackgroundColor:[UIColor colorWithWhite:0.5 alpha:0.5]];

最后,当您想摆脱“变灰”效果时,只需将 View 设置回清晰即可:

[grayOverlay setBackgroundColor:[UIColor clearColor]];

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

关于objective-c - 使用 UISearchBar 时使 View 的其余部分变灰,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11440882/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com