我如何为borderWidth自定义所有UITextField外观? [英] How may i customise all UITextField appearances for borderWidth?

查看:120
本文介绍了我如何为borderWidth自定义所有UITextField外观?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试自定义borderWith的所有UITextField外观。

i am trying to customise all UITextField appearances for borderWith.

尝试类似的方法。
只有前2行有所作为。
其余行不起作用?

Trying something like this. Only first 2 lines are making a difference. Rest of the lines not working ?

[[UITextField appearance] setBackgroundColor:[UIColor greenColor]];
[[UITextField appearance] setTextColor:[UIColor blackColor]];
[UITextField appearance].layer.cornerRadius = 6.0f;
[UITextField appearance].layer.borderColor = [UIColor redColor].CGColor;
[UITextField appearance].layer.borderWidth = 3.f;


推荐答案

不幸的是,外观代理无法在做您想做的事情,您应该继承UITextField并在layoutSubviews方法(或init)中进行自定义

Unfortunately the appearance proxy doesn't work on layers to do what you want you should subclass UITextField and do your customisations in the layoutSubviews method (or in the init)

这篇关于我如何为borderWidth自定义所有UITextField外观?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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