zoukankan      html  css  js  c++  java
  • 设置UITextField占位符的颜色和字体

     

     

    今天刚学了UITextField控件, 感觉在里面设置占位符非常好, 给用户提示信息, 于是就在想占位符的字体和颜色能不能改变呢?

    下面是小编的一些简单的实现.

    主要有两种方法:

    方法1:利用富文本

    @property (weak, nonatomic) IBOutlet UITextField *textField;

     NSDictionary *dic = @{NSForegroundColorAttributeName:[UIColor magentaColor], NSFontAttributeName:[UIFont systemFontOfSize:15]};

     self.textField.attributedPlaceholder = [[NSAttributedString alloc] initWithString:@"欢迎回来" attributes:dic];

     self.textField.tintColor = [UIColor cyanColor];

    方法2:KVC

    self.textField.placeholder = @"欢迎回来!";

     [self.textField setValue:[UIColor magentaColor] forKeyPath:@"_placeholderLabel.textColor"]

     [self.textField setValue:[UIFont systemFontOfSize:15] forKeyPath:@"_placeholderLabel.font"];

     self.textField.tintColor = [UIColor greenColor];

    KVC功能很多呦, 还可以实现数组简单的求和

    NSArray *dataArray = @[@"1", @"2", @"3", @"4", @"5"];

     NSNumber *sum = [dataArray valueForKeyPath:@"@sum.integerValue"];

     NSLog(@"%@", sum);

     
     
  • 相关阅读:
    Django之admin
    Django之CSRF(跨站请求伪造)
    Django之Cookie
    Django之Session
    Django|第一部
    简单的udp消息收发
    .net core里使用ado.net访问sqlserver数据库
    CentOS8中安装SQLServer
    CentOS里配置.net core运行环境(含后台运行,附ssh长连接)
    发布"dotNet core"到CentOS8
  • 原文地址:https://www.cnblogs.com/hsxblog/p/5140368.html
Copyright © 2011-2022 走看看