//  CustomField.h
#import <UIKit/UIKit.h>
@interface CustomField : UITextField
@end
//  CustomField.m

#import "CustomField.h"

@implementation CustomField

- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
// Initialization code
}
return self;
} /*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
*/
- (void)drawRect:(CGRect)rect
{
// Drawing code
} -(CGRect)clearButtonRectForBounds:(CGRect)bounds
{
return CGRectMake(bounds.origin.x +bounds.size.width - ,bounds.origin.y+bounds.size.height/-/, , );
}
//bounds.size.height -20
//控制placeHolder的位置,左右缩20
-(CGRect)placeholderRectForBounds:(CGRect)bounds
{
//return CGRectInset(bounds,20, 0);
CGRect inset= CGRectMake(bounds.origin.x+, bounds.origin.y+, bounds.size.width -, bounds.size.height);
return inset;
}
//控制显示文本的位置
-(CGRect)textRectForBounds:(CGRect)bounds
{
CGRect inset= CGRectMake(bounds.origin.x+, bounds.origin.y, bounds.size.width -, bounds.size.height);//更好理解些 return inset; }
//控制编辑文本的位置
-(CGRect)editingRectForBounds:(CGRect)bounds
{
//return CGRectInset(bounds, 10 , 0 ); CGRect inset= CGRectMake(bounds.origin.x +, bounds.origin.y, bounds.size.width -, bounds.size.height);
return inset;
}
//控制左视图位置
- (CGRect)leftViewRectForBounds:(CGRect)bounds
{
CGRect inset= CGRectMake(bounds.origin.x +, bounds.origin.y, bounds.size.width-, bounds.size.height);
return inset;
//returnCGRectInset(bounds,50,0);
} - (CGRect)rightViewRectForBounds:(CGRect)bounds;
{
CGRect inset= CGRectMake(bounds.origin.x +bounds.size.width-, bounds.origin.y+bounds.size.height/-,,);
return inset;
} //控制placeHolder的颜色、字体
- (void)drawPlaceholderInRect:(CGRect)rect
{
//CGContextRef context =UIGraphicsGetCurrentContext();
//CGContextSetFillColorWithColor(context,[UIColor yellowColor].CGColor);
[[UIColor brownColor] setFill]; [[self placeholder] drawInRect:rect withFont:[UIFont systemFontOfSize:]]; }
@end // 使用方法,在XXXViewController里导入#import "CustomField.h" CustomField *myField=[[CustomField alloc]init];

最新文章

  1. 关于XSS(跨站脚本攻击)和CSRF(跨站请求伪造)
  2. EventBus使用详解(一)
  3. BZOJ 1030 【JSOI2007】 文本生成器
  4. centOS下yum安装配置samba
  5. fill_parent和wrap_content的区别
  6. FF与IE对JavaScript和CSS的区别
  7. 关于Objective-C 对象release操作的一个小问题探讨
  8. Object Pascal对象模型中构造函数之研究
  9. openerp 经典收藏 通过view实现字段的只读、隐藏操作(转载)
  10. MAC Intellij IDEA 常用快捷键
  11. Hibernate 系列教程16-二级缓存
  12. Java基础语法&lt;九&gt; 接口与内部类
  13. Cookie简述
  14. BZOJ 1801: [Ahoi2009]chess 中国象棋 [DP 组合计数]
  15. 一步一步设置Joomla!开发环境
  16. pdf下载速度
  17. django from表单验证
  18. 41)django-admin
  19. CentOS安装mariadb做为mysql的替代品
  20. 左侧多级菜单,高亮显示js

热门文章

  1. OpenGL ES 三种类型 uniform attribute varying
  2. Oracle EBS-SQL (PO-11):检查采购订单退货数.sql
  3. Balsamiq Mockups registration code
  4. Android 为应用添加数字角标
  5. Android 微信分享信息
  6. 有关UNICODE、ANSI字符集和相关字符串操作
  7. iOS中如何呼出另一个应用
  8. centos6.5 Eclipse C/C++开发环境及项目创建测试
  9. Java WebService把Date类型转换成XMLGregorianCalendar
  10. 在centos中添加开机自启动服务