UITextField clearButtonMode颜色 [英] UITextField clearButtonMode color

查看:2221
本文介绍了UITextField clearButtonMode颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可予改变clearButtonMode的颜色上包含textField?

can I change the color of the clearButtonMode on a textField?

theTextField.clearButtonMode = UITextFieldViewModeWhileEditing

显示一个灰色深色的x,用于删除textField,

shows an x that is grey dark color to delete the textField,

但是我可以用白色显示这个按钮吗?

but can i show this button with white color?

谢谢

推荐答案

在这种情况下,您需要创建自己的清除按钮图像。我建议拍摄清晰按钮的屏幕截图并在photoshop中进行编辑。

You'll need to create your own clear button image in this case. I would suggest taking a screenshot of the clear button and editing in photoshop.

您可以拍摄该图像并使用图像尺寸创建UIButton。从那里你可以将它设置为UITextField的rightView。像这样:

You can take that image and create a UIButton with the image dimensions. From there you can set it as the UITextField's rightView. Like so:

UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
[button setImage:[UIImage imageNamed:@"clear_button.png"] forState:UIControlStateNormal];
[button setFrame:CGRectMake(0.0f, 0.0f, 15.0f, 15.0f)]; // Required for iOS7
theTextField.rightView = button;
theTextField.rightViewMode = UITextFieldViewModeWhileEditing;

我在没有语法检查的情况下键入了这个,但是在运行它之前你不想这么做。您还需要将clear_button.png替换为您的图像名称。

I typed that without syntax checking and what not so you'll want to check it out before running it. You'll also want to replace clear_button.png with whatever your image name is.

您还需要编写自己的方法来清除文本字段。

You'll also need to write your own method to clear the text field.

这篇关于UITextField clearButtonMode颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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