修改UITextField Placeholder的颜色

修改UITextField Placeholder的颜色

  • 1 第一种情况只是修改颜色等文字属性

    • 创建属性字典
         NSDictionary *attrsDic = @{ NSForegroundColorAttributeName : [UIColor colorWithRed:106/255.0 green:114/255.0 blue:117/255.0 alpha:1],NSFontAttributeName:[UIFont systemFontOfSize:15] };
      
    • 创建属性字符串
         NSAttributedString *str = [[NSAttributedString alloc] initWithString:@"anything" attributes:attrsDic];
      
    • 赋值给textfield的attributedPlaceholder属性
         _txt.attributedPlaceholder = str;	
      
  • 2 第二种情况改颜色和Placeholder位置

    • 继承UITextField

    • 重写drawPlaceholderInRect:方法

    • 设置颜色和位置等

        [colour setFill];
        rect = CGRectMake(0, 0, 0, 0);//修改位置
        [_txtOldPassWord.placeholder drawInRect:rect withFont:_txtOldPassWord.font lineBreakMode:NSLineBreakByTruncatingTail alignment:_txtOldPassWord.textAlignment];
      

posted on 2015-01-14 17:25  myWythe  阅读(248)  评论(0编辑  收藏  举报

导航