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

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

而在实际开发中为了让视觉效果更统一,我们可能会想把那光标的颜色设置成和界面色调一致的颜色。其实在 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

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

相关文章:

  • 2021-11-27
  • 2022-12-23
  • 2022-12-23
  • 2021-08-24
  • 2022-12-23
  • 2022-02-18
  • 2022-12-23
猜你喜欢
  • 2021-09-05
  • 2022-12-23
  • 2022-12-23
  • 2021-07-03
  • 2021-08-16
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案