zoukankan      html  css  js  c++  java
  • ios 设置UITextField的placeholder大小颜色

    需求:产品嫌弃placeholder的字体太大,颜色太明显,要求跟正常输入时的字体及颜色不同

    方法:设置placeholder的大小和颜色,实际上是设置placeholder的label的大小和颜色,但是当设置完之后,placeholder的字体有点偏上了,所以设置一下属性。

       // 设置placeholder的字体大小
        [titleField setValue:[UIFont systemFontOfSize:13] forKeyPath:@"_placeholderLabel.font"];
        // 设置placeholder的字体颜色
        [titleField setValue:[UIColor redColor] forKeyPath:@"_placeholderLabel.textColor"];
        // placeholder居中显示
        NSMutableParagraphStyle *style = [titleField.defaultTextAttributes[NSParagraphStyleAttributeName] mutableCopy];
        style.minimumLineHeight = titleField.font.lineHeight - (titleField.font.lineHeight - [UIFont systemFontOfSize:13].lineHeight) / 2;
        titleField.attributedPlaceholder = [[NSAttributedString alloc] initWithString:@"请在此输入标题" attributes:@{NSParagraphStyleAttributeName : style}];

    问题:嫌弃输入文字不居中,placeholder不居中
    方法:重写!重写解决一切问题!

     -(CGRect)editingRectForBounds:(CGRect)bounds
    
     -(CGRect)placeholderRectForBounds:(CGRect)bounds
    

      



  • 相关阅读:
    Docker学习笔记-Redis 安装
    CentOS搭建FTP服务
    Docker学习笔记-Docker for Windows 安装
    Docker学习笔记-Docker for Linux 安装
    (转载)Javascript 中的非空判断 undefined,null, NaN的区别
    MongoDB
    RabbitMQ
    GIT学习笔记——常用命令
    Evanyou Blog 彩带
    Evanyou Blog 彩带
  • 原文地址:https://www.cnblogs.com/peaker-wu/p/5474674.html
Copyright © 2011-2022 走看看