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

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

   // 设置placeholder的字体大小
[titleField setValue:[UIFont systemFontOfSize:] 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:].lineHeight) / ;
titleField.attributedPlaceholder = [[NSAttributedString alloc] initWithString:@"请在此输入标题" attributes:@{NSParagraphStyleAttributeName : style}];

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

 -(CGRect)editingRectForBounds:(CGRect)bounds

 -(CGRect)placeholderRectForBounds:(CGRect)bounds

  

ios 设置UITextField的placeholder大小颜色的更多相关文章

  1. 设置UITextField的placeholder的颜色

    [textField setValue:[UIColor redColor] forKeyPath:@"_placeholderLabel.textColor"];

  2. [BS-19]更改UITextField的placeholder文字颜色的5种方法

    更改UITextField的placeholder文字颜色的5种方法 想要达到的目标是:一个页面上有多个UITextField,当用户聚焦某textField时,该文本框的placeholder的文字 ...

  3. IOS设置导航栏字体大小及颜色

    方法一: 自定义视图,定义一个lable,相关属性在lable里设置 核心方法: self.navigationItem.titleView = titleLabel; 方法二:用系统方法直接设置 [ ...

  4. iOS 修改UITextField的placeholder属性的字体颜色(修改UITextField占位符字体的颜色)

    只要把原来的placeholder属性改为attributedPlaceholder属性即可 具体代码如下图:

  5. 设置input标签placeholder字体颜色

    有时会遇到这样的需求,输入框的默认提示文字与用户输入的文字不同. <input className="city" placeholder="城市"/> ...

  6. iOS设置cell选中时文字颜色的变化

    cell.titleStr.highlightedTextColor = EMCGreenColor;

  7. iOS 设置UITextView的Placeholder

    代码如下: - (void)setupTextView { UITextView *textView = [[UITextView alloc] initWithFrame:CGRectMake(0, ...

  8. 修改UITextfield的Placeholder字体的颜色

    - (void)viewDidLoad { [super viewDidLoad]; self.title=@"修改UITextField的placeholder字体颜色"; UI ...

  9. css设置input中placeholder字体

    设置input中placeholder字体颜色 input::-webkit-input-placeholder {color:@a;} input:-moz-placeholder {color:@ ...

随机推荐

  1. python期末考试复习

    期末考试复习 补修的python跟着大一一起学,考试肯定不会出难,于是就敲了一些代码,把他们放到博客上,来记录一下 代码都是一段一段的,且python代码不是很多,所以我都写到了一个文件里,作为练习 ...

  2. 墙壁涂色(DP)

    蒜头君觉得白色的墙面好单调,他决定给房间的墙面涂上颜色. 他买了 3 种颜料分别是红.黄.蓝,然后把房间的墙壁竖直地划分成 n 个部分,蒜头希望每个相邻的部分颜色不能相同. 他想知道一共有多少种给房间 ...

  3. windows更新系统系统时无法更新

    win7系统显示“windows update当前无法检查更新,因为未运行服务,您可能需要重新启动计算机” 解决方法 1.win+r打开运行窗口,输入CMD 2.在dos窗口中输入命令“net sto ...

  4. VNC viewer 无法打开oracle 11g图形界面方案

    VNC viewer 无法打开oracle 11g图形界面方案 1.检查交换空间失败 检查交换空间:可用的交换空间为35MB,所需的交换空间为150MB.未通过 创建swapfile: root权限下 ...

  5. os简介

    1. 操作系统(Operation System,OS) 操作系统作为接口的示意图  没有安装操作系统的计算机,通常被称为 裸机 如果想在 裸机 上运行自己所编写的程序,就必须用机器语言书写程序 如 ...

  6. 【MySQL参数】-innodb_buffer_pool_chunk_size

    如果 初始化缓冲池时 innodb_buffer_pool_chunk_size* innodb_buffer_pool_instances大于当前缓冲池大小, innodb_buffer_pool_ ...

  7. 正确返回Unicode码点大于0xFFFF的字符串长度

    如下: function codePointLength(text){ var result = text.match(/[\s\S]/gu); return result? result.lengt ...

  8. hasura graphql-engine v1.2.0 beta 版本

    hasura graphql-engine v1.2.0 提供了一个很不错的功能action,这个也是目前其他graphql 没有hasura 强大的 地方,使用action 我们可以更好的扩展has ...

  9. 微信小程序生成海报保存图片到相册小测试

    test.wxml <canvas style="width:{{imageWidth}}px;height:{{imageHeight}}px;" canvas-id=&q ...

  10. python代码实现购物车(django的redis与vue)

    安装模块 pip install django-redis 后端代码 # 购物车 class CartView(APIView): # 初始化函数 def __init__(self): self.c ...