参考:http://blog.csdn.net/a394318511/article/details/8025170
写一个UITextField的父类,重写UITextField内部边界绘制方法,更新UITextField内部控件布局
#import "CustomTextField.h" @implementation CustomTextField //控制清除按钮的位置 -(CGRect)clearButtonRectForBounds:(CGRect)bounds { return CGRectMake(bounds.origin.x + bounds.size.width - 55, bounds.origin.y, bounds.size.height, bounds.size.height); } //控制左视图位置 - (CGRect)leftViewRectForBounds:(CGRect)bounds { CGRect inset = CGRectMake(bounds.size.width-30, bounds.origin.y, bounds.size.width-250, bounds.size.height); return inset; } //控制显示文本的位置 -(CGRect)textRectForBounds:(CGRect)bounds { CGRect inset = CGRectMake(bounds.origin.x+10, bounds.origin.y, bounds.size.width -10, bounds.size.height); return inset; } //控制编辑文本的位置 -(CGRect)editingRectForBounds:(CGRect)bounds { CGRect inset = CGRectMake(bounds.origin.x +10, bounds.origin.y, bounds.size.width -10, bounds.size.height); return inset; } @end