UITextField的leftView和rightView属性

4 篇文章 0 订阅
[objc]  view plain  copy
  1. tf = [[UITextField alloc]init];  
  2. tf.backgroundColor = [UIColor cyanColor];  
  3. tf.frame = CGRectMake(505010020);  
  4. UIImageView *imagev = [[UIImageView alloc]initWithFrame:CGRectMake(002020)];  
  5. imagev.image = [UIImage imageNamed:@"nb"];  
  6. tf.rightView = imagev;  
  7. tf.rightViewMode = UITextFieldViewModeAlways;  
  8.   
  9.   
  10. UILabel *paddingLb = [[UILabel alloc] initWithFrame:CGRectMake(001025)];  
  11. paddingLb.text = @"$";  
  12. paddingLb.textColor = [UIColor darkGrayColor];  
  13. paddingLb.backgroundColor = [UIColor clearColor];  
  14. tf.leftView = paddingLb;  
  15. tf.leftViewMode = UITextFieldViewModeAlways;//必不可少  
  16. [self.view addSubview:tf];  

参考文章:http://blog.csdn.net/wanglang3081/article/details/7464943

**********************************2015年10月13日更新****************************************************************************************************************************************


之前设置的图片距离右边界没有空隙,能够增加空隙的代码

[objc]  view plain  copy
  1. UITextField *searchBar = [[UITextField alloc]init];  
  2. searchBar.frame = CGRectMake(00self.view.bounds.size.width - 4*padding, 30);  
  3. UIImageView*searchImgV =[[UIImageView alloc]initWithImage:[UIImage imageWithName:@"searchbar_textfield_search_icon"]];  
  4. searchImgV.contentMode = UIViewContentModeCenter;  
  5. searchImgV.frame = CGRectMake(003030);  
  6. searchBar.leftView = searchImgV;  


第一段代码效果:


第二段代码效果:

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值