?
- .h??
- ??
- ??
- ??
- ??
- ??
- ??
- ??
- ??
- #import?<UIKit/UIKit.h>??
- ??
- @interface?TextField?:?UITextField??
- ??
- @property?(nonatomic,?assign)?CGFloat?dx;??
- @property?(nonatomic,?assign)?CGFloat?dy;??
- ??
- @end??
?
?
- .m??
- ??
- ??
- ??
- ??
- ??
- ??
- ??
- ??
- #import?"TextField.h"??
- ??
- #define?kTextFieldPaddingWidth??(10.0f)??
- #define?kTextFieldPaddingHeight?(10.0f)??
- ??
- @implementation?TextField??
- ??
- -?(id)initWithFrame:(CGRect)frame??
- {??
- ????self?=?[super?initWithFrame:frame];??
- ????if?(self)?{??
- ??????????
- ????}??
- ????return?self;??
- }??
- ??
- -?(CGRect)textRectForBounds:(CGRect)bounds??
- {??
- ????return?CGRectInset(bounds,??
- ???????????????????????self.dx?==?0.0f???kTextFieldPaddingWidth?:?self.dx,??
- ???????????????????????self.dy?==?0.0f???kTextFieldPaddingHeight?:?self.dy);??
- }??
- ??
- -?(CGRect)editingRectForBounds:(CGRect)bounds??
- {??
- ????return?CGRectInset(bounds,??
- ???????????????????????self.dx?==?0.0f???kTextFieldPaddingWidth?:?self.dx,??
- ???????????????????????self.dy?==?0.0f???kTextFieldPaddingHeight?:?self.dy);??
- }??
- ??
- -?(void)setDx:(CGFloat)dx??
- {??
- ????_dx?=?dx;??
- ????[self?setNeedsDisplay];??
- }??
- ??
- -?(void)setDy:(CGFloat)dy??
- {??
- ????_dy?=?dy;??
- ????[self?setNeedsDisplay];??
- }??
- ??
- ?
- ?
- ?
- ?
- ?
- ?
- ?
- ??
- ??
- @end??
?
2.APPLE private method.
[self.yourTextField?setValue:[NSNumber?numberWithInt:5]?forKey:@"_paddingTop"];
[self.yourTextField?setValue:[NSNumber?numberWithInt:5]?forKey:@"_paddingLeft"];
[self.yourTextField?setValue:[NSNumber?numberWithInt:5]?forKey:@"_paddingBottom"];
[self.yourTextField?setValue:[NSNumber?numberWithInt:5]?forKey:@"_paddingRight"];