一行代码轻松修改 Text Field 和 Text View 的光标颜色 — By 昉

众所周知,Text Field 和 Text View 的光标颜色默认都是系统应用的那种蓝色,如图:

而在实际开发中为了让视觉效果更统一,我们可能会想把那光标的颜色设置成和界面色调一致的颜色。其实在 iOS 7 以后只需要一行代码便可以轻松实现:

view.tintColor = [UIColor greenColor];  // view是你要修改的 Text Field 或 Text View

 

或者使用UIAppearance代理直接修改App中所有实例的光标颜色:

[[UITextField appearance] setTintColor:[UIColor greenColor]];  // Text Field

//

[[UITextView appearance] setTintColor:[UIColor greenColor]];  // Text View

 

posted @ 2015-05-09 11:38  sixindev  阅读(461)  评论(0编辑  收藏  举报