gpt4 book ai didi

iphone - UISearchBar 中范围按钮文本的颜色

转载 作者:可可西里 更新时间:2023-11-01 06:18:16 26 4
gpt4 key购买 nike

我有一个 UISearchBar,它必须具有灰色调。

我现在遇到的问题是,一旦我设置了任何色调颜色,示波器按钮就会获得相同的字体颜色,如果按钮不是这样的话,会导致对比度很差已选中。

如果未设置色调,则颜色会根据所选状态而变化。有没有一种方法可以使用色调来实现这一点?

默认值

with tint

使用色调

no tint

更新

使用 po [mySearchBar recursiveDescription] 我发现 UISearchbar 具有以下 View 层次结构:

<UISegmentedControl>
<_UISegmentedControlBackgroundView>
<UIImageView>
<UISegment>
<UISegmentLabel>
<UIImageView>
<UISegment>
<UISegmentLabel>
<UIImageView>
<UISegment>
<UISegmentLabel>
<UIImageView>
<UISearchBarBackground>

最佳答案

我似乎记得在使用淡色时遇到过类似的问题。似乎一个不幸的副作用是它默认它影响的 UIKit 元素的颜色相关属性。

我不知道在使用色调时是否有办法防止这种缺陷(我认为没有),但以下解决方法可能对您有用:

iOS 6 及以下

[searchBar setScopeBarButtonTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIColor redColor], UITextAttributeTextColor, nil] forState:UIControlStateNormal];
[searchBar setScopeBarButtonTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIColor greenColor], UITextAttributeTextColor, nil] forState:UIControlStateSelected];

iOS 7+

[searchBar setScopeBarButtonTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIColor redColor], NSForegroundColorAttributeName, nil] forState:UIControlStateNormal];
[searchBar setScopeBarButtonTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIColor greenColor], NSForegroundColorAttributeName, nil] forState:UIControlStateSelected];

(来源:@willyang)

使用 UISearchBarsetScopeBarButtonTitleTextAttributes:forState: 方法,您可以配置范围栏按钮标题的属性,包括文本颜色。

关于iphone - UISearchBar 中范围按钮文本的颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15385050/

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