更改 ABPeoplePickerNavigationController 内 UISearchBar 的tintColor
我正在尝试在 ABPeoplePickerNavigationController
中自定义颜色,下面是我的完整代码:
ABPeoplePickerNavigationController *objPeoplePicker = [[ABPeoplePickerNavigationController alloc] init];
[objPeoplePicker setPeoplePickerDelegate:self];
objPeoplePicker.topViewController.navigationController.navigationBar.tintColor = [UIColor colorWithRed:0.294 green:0.278 blue:0.247 alpha:1.0];
objPeoplePicker.topViewController.searchDisplayController.searchBar.tintColor = [UIColor colorWithRed:0.294 green:0.278 blue:0.247 alpha:1.0];
[self presentModalViewController:objPeoplePicker animated:YES];
自定义导航栏的色调颜色,此行有效:
objPeoplePicker.topViewController.navigationController.navigationBar.tintColor = [UIColor colorWithRed:0.294 green:0.278 blue:0.247 alpha:1.0];
但是,我还想自定义搜索栏的色调颜色
objPeoplePicker.topViewController.searchDisplayController.searchBar.tintColor = [UIColor colorWithRed:0.294 green:0.278 blue:0.247 alpha:1.0];
:线不工作。我想我可能引用了错误的搜索栏......你能指出我正确的方向吗?
I am tyring to customize the colors a bit in a ABPeoplePickerNavigationController
below is my complete code:
ABPeoplePickerNavigationController *objPeoplePicker = [[ABPeoplePickerNavigationController alloc] init];
[objPeoplePicker setPeoplePickerDelegate:self];
objPeoplePicker.topViewController.navigationController.navigationBar.tintColor = [UIColor colorWithRed:0.294 green:0.278 blue:0.247 alpha:1.0];
objPeoplePicker.topViewController.searchDisplayController.searchBar.tintColor = [UIColor colorWithRed:0.294 green:0.278 blue:0.247 alpha:1.0];
[self presentModalViewController:objPeoplePicker animated:YES];
Customizing the NavigationBar tintColor, this line works:
objPeoplePicker.topViewController.navigationController.navigationBar.tintColor = [UIColor colorWithRed:0.294 green:0.278 blue:0.247 alpha:1.0];
But, I'd also like to customize the tintColor of the searchBar:
objPeoplePicker.topViewController.searchDisplayController.searchBar.tintColor = [UIColor colorWithRed:0.294 green:0.278 blue:0.247 alpha:1.0];
That line does not work. I think I may be referencing the wrong searchBar....can you point me in the right direction?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我刚刚遇到了同样的问题。更改导航栏颜色很容易。但更改 UISearchBar 颜色的幅度不大。首先我做的是检查
searchDisplayController 两次都是 nil。我最终做的是遍历视图层次结构以找到 UISearchBar 视图。肯定有一个是对的。这是我的最终代码。如果有人有更好的解决方案,我很想听听。
I just ran into the same problem. Changing the navBar color is easy. Changing the UISearchBar color however not so much. First what I did was to check
Both times the searchDisplayController was nil. What I ended up doing was traversing the view hierarchy to find the UISearchBar view. There is certainly one there right. So this is my final code. If anyone has a better solution I would love to hear it.
我没有更改颜色,而是将图像添加到背景中:
Instead of changing the color I add an image to the background:
您现在可以使用 UISearchBar 外观代理来执行此操作:
You can do this using the UISearchBar appearance proxy now:
对于 iOS7+,最简单的方法是操作
UISearchBar
的外观代理:For iOS7+ the easiest way is manipulating the appearance proxy of the
UISearchBar
: