继承UITextfield,覆盖父类方法,使用自定义的GCTextField创建控件
- #import <UIKit/UIKit.h>
- @interface GCTextField : UITextField
- - (CGRect)textRectForBounds:(CGRect)bounds;
- - (CGRect)editingRectForBounds:(CGRect)bounds;
- @end
- #import "GCTextField.h"
- @implementation InsetsTextField
- //控制文本所在的的位置,左右缩 10
- - (CGRect)textRectForBounds:(CGRect)bounds {
- return CGRectInset( bounds , 10 , 0 );
- }
- //控制编辑文本时所在的位置,左右缩 10
- - (CGRect)editingRectForBounds:(CGRect)bounds {
- return CGRectInset( bounds , 10 , 0 );
- }
- @end