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);

     
     
  • 相关阅读:
    QPushbutton样式
    qt调动DLL
    QLabel设置行间距
    Qt 5.2.1 applications (32 bit) in CentOS (64 bit with gcc 4.8.2)
    qt设置阴影效果
    ubuntu命令
    How to configure NFS on Linux
    gsoap生成onvif c++源码
    QUrl乱码问题
    QTableWidget自适应标题(铺满、可调节)
  • 原文地址:https://www.cnblogs.com/hsxblog/p/5140368.html
Copyright © 2011-2022 走看看