UITextField的leftView和rightView属性
2015-10-11 23:51
489 查看
tf = [[UITextField alloc]init]; tf.backgroundColor = [UIColor cyanColor]; tf.frame = CGRectMake(50, 50, 100, 20); UIImageView *imagev = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 20, 20)]; imagev.image = [UIImage imageNamed:@"nb"]; tf.rightView = imagev; tf.rightViewMode = UITextFieldViewModeAlways; UILabel *paddingLb = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 10, 25)]; paddingLb.text = @"$"; paddingLb.textColor = [UIColor darkGrayColor]; paddingLb.backgroundColor = [UIColor clearColor]; tf.leftView = paddingLb; tf.leftViewMode = UITextFieldViewModeAlways;//必不可少 [self.view addSubview:tf];
参考文章:http://blog.csdn.net/wanglang3081/article/details/7464943
**********************************2015年10月13日更新****************************************************************************************************************************************
之前设置的图片距离右边界没有空隙,能够增加空隙的代码
UITextField *searchBar = [[UITextField alloc]init]; searchBar.frame = CGRectMake(0, 0, self.view.bounds.size.width - 4*padding, 30); UIImageView*searchImgV =[[UIImageView alloc]initWithImage:[UIImage imageWithName:@"searchbar_textfield_search_icon"]]; searchImgV.contentMode = UIViewContentModeCenter; searchImgV.frame = CGRectMake(0, 0, 30, 30); searchBar.leftView = searchImgV;
第一段代码效果:
第二段代码效果:
相关文章推荐
- STL之priority_queue实现
- STL之queue实现
- STL之deque实现
- sciprts.jsp for requirejs
- requireJS config.js
- popViewControllerAnimated 后,对页面内UITableView 内数据刷新
- 构建android UI 学习心得,摘要
- request.getPathInfo();
- Twenty Questions
- EasyUI - Panel 面板控件
- hdu 5496 Beauty of Sequence(高效)
- UIKit
- 有了Auto Layout,为什么你还是害怕写UITabelView的自适应布局?
- UI基础总结第一天
- 【IOS 开发学习总结-OC-43】★ios开发——UIButton(按钮)与 UISwitch(开关按钮)
- UI设计十戒--设计师的艺术
- UI交互设计体验--未来声控之路?
- UIButton 文字显示位置设置 字体的大小设置 字体的颜色设置 注意事项
- 移动界面UI颜色设计
- iOS开发- UICollectionView详解+实例