在UITextField开始加空格
来源:互联网 发布:网易博客发帖软件 编辑:程序博客网 时间:2024/06/05 10:01
APP中经常用到UITextField,placeholder和text都是从最左边开始,看起来很不美观。想要在文本之前添加一个起始空格。
方法:
重写UITextFiled的两个方法,生成一个子类:
#import "HeaderEmptyTextField.h"@implementation HeaderEmptyTextField- (CGRect)textRectForBounds:(CGRect)bounds{ return CGRectInset(bounds, 15, 0);}- (CGRect)editingRectForBounds:(CGRect)bounds{ return CGRectInset(bounds, 15, 0);}@end
这时,在创建UITextFiled的代码中加一个参数
- (UITextField *)createTextFieldWithFrame:(CGRect)textFieldFrame Font:(CGFloat)font textColor:(UIColor *)textColor Placeholder:(NSString *)placeholder headerEmpty:(BOOL)isEmpty{ if (isEmpty) { HeaderEmptyTextField *textField = [[HeaderEmptyTextField alloc]initWithFrame:textFieldFrame]; textField.textColor = textColor; textField.font = [UIFont systemFontOfSize:font]; textField.borderStyle = UITextBorderStyleNone; textField.placeholder = placeholder; return textField; }else{ UITextField *textField = [[UITextField alloc]initWithFrame:textFieldFrame]; textField.textColor = textColor; textField.font = [UIFont systemFontOfSize:font]; textField.borderStyle = UITextBorderStyleNone; textField.placeholder = placeholder; return textField; } }
这样,在外部直接传一个BOOL值,需要前面加空格的时候传YES,否则传NO,外部不需要知道是用HeaderEmptyTextField还是用UITextField,统一用UITextField,因为UITextField是父类。
0 0
- 在UITextField开始加空格
- 怎样在汉字后面加空格?
- UITextField四位加一个空格
- iOS UItextField去除空格
- word在特定页开始加页码
- Android开发在xml资源文件中加空格
- UITextField填写电话号码 添加空格
- iOS 去掉UITextField前后空格
- UITextField设置无法输入空格
- UITextField手机号中间自动空格
- UITextField在弹出的键盘上方,加一个带有完成按钮的toolBar工具栏
- XML里面加空格
- markdown加空格
- .properties 配置文件 加空格
- UITextField的左边的占位空格
- UITextfield 禁止输入空格的做法
- 输入框UITextField禁止输入空格
- ios新手入门之UITextField左边空格
- Android自动测试命令Monkey
- POJ 1985 Cow Marathon(牛的锻炼,树的直径)
- 双向队列
- [LeetCode] 77. Combinations
- 《WINDOWSPE权威指南》学习笔记(二)- PE文件结构及字段说明
- 在UITextField开始加空格
- 【笔试面试】第二波
- 一、大神与二货系列之indexOf(一)
- 23种设计模式
- struts2中如何将json格式的数据传到前端呢??json-default就是你要找的答案
- python开发简单爬虫:实战篇
- java 遍历resultset报错: peration not allowed after ResultSet closed【整理】
- fastdfs分布式文件系统之Storage server介绍
- Centos6.5下配置NFS存储