ios开发——UITextField中设置placeholder字体颜色

设置placeholder字体颜色 


声明TextField时,往往由于背景的原因,默认的placeholder字体颜色不够清晰,这里是直接设置placeholder的颜色属性

[objc]  view plain copy print ?
  1. //搜索框设置  
  2. UITextField *searchTxt = [[UITextField alloc] initWithFrame:CGRectMake(155826030)];  
  3. [searchTxt setBackground:[UIImage imageNamed:@"inPutBackground.jpg"]];  
  4.   
  5. //设置提示字符  
  6. [searchTxt setPlaceholder:@"请输入关键字..."];  
  7.   
  8. bsp; //设置placeholder的颜色,其中的_placeholderLabel.textColor是系统自带的,可以直接使用  
  9. [searchTxt setValue:[UIColor grayColor] forKeyPath:@"_placeholderLabel.textColor"];  
  10.   
  11. //设置光标颜色  
  12. [searchTxt setTintColor:[UIColor whiteColor]];  
  13.   
  14. //设置输入字体颜色  
  15. [searchTxt setTextColor:[UIColor whiteColor]];  
  16.   
  17. [self.view addSubview:searchTxt];  


附图:


默认时效果



设置后效果




注:随手笔记,不严谨,以后发现错误立即更改


转载:http://blog.youkuaiyun.com/wsyx768/article/details/19755955




效果图:

代码:

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    
    
    UITextField *textField=[[UITextField alloc]initWithFrame:CGRectMake(50, 100, 200, 50)];
    
    //UITextField设置placeholder颜色
    UIColor *color = [UIColor redColor];
    textField.attributedPlaceholder = [[NSAttributedString alloc] initWithString:@"密码" attributes:@{NSForegroundColorAttributeName: color}];
    
    textField.delegate=self;
    [self.view addSubview:textField];
    
}

转载:http://www.bkjia.com/IOSjc/920391.html
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值