如何在 iOS7 中更改 UISearchBar 的取消按钮的 textColor? [英] How to change textColor of Cancel button of UISearchBar in iOS7?

查看:19
本文介绍了如何在 iOS7 中更改 UISearchBar 的取消按钮的 textColor?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要更改iOS7中UISearchBar的取消按钮文本的颜色.

I need to change the color of Cancel button text of UISearchBar in iOS7.

通常 UISearchBar 取消按钮 textColor 是蓝色的,我想将 textColor 更改为 redColor.

Normally UISearchBar Cancel button textColor is blue and I want to change textColor to redColor.

我该如何更改?

推荐答案

我找到了自己问题的答案.

I found answers for my own questions.

这是代码,如果要更改所有取消按钮,请添加AppDelegate.

Here is code , add in AppDelegate if you want to change all cancel button.

[[UIBarButtonItem appearanceWhenContainedIn:[UISearchBar class], nil] setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:
                                                                                                  [UIColor redColor],
                                                                                                  UITextAttributeTextColor,
                                                                                                  [UIColor whiteColor],
                                                                                                  UITextAttributeTextShadowColor,
                                                                                                  [NSValue valueWithUIOffset:UIOffsetMake(0, 1)],
                                                                                                  UITextAttributeTextShadowOffset,
                                                                                                  nil]
                                                                                        forState:UIControlStateNormal];

斯威夫特:

let attributes = [NSForegroundColorAttributeName : UIColor.red]
    UIBarButtonItem.appearance(whenContainedInInstancesOf: [UISearchBar.self]).setTitleTextAttributes(attributes, for: .normal)

这篇关于如何在 iOS7 中更改 UISearchBar 的取消按钮的 textColor?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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