码迷,mamicode.com
首页 > 移动开发 > 详细

iOS UITextField 设置内边距

时间:2015-06-19 18:12:35      阅读:706      评论:0      收藏:0      [点我收藏+]

标签:

http://blog.csdn.net/erica_sadun/article/details/9088181
1.inherit UITextField Class.

?

  1. .h??
  2. //??
  3. //??TextField.h??
  4. //??TTShow??
  5. //??
  6. //??Created?by?twb?on?13-9-10.??
  7. //??Copyright?(c)?2013年?twb.?All?rights?reserved.??
  8. //??
  9. ??
  10. #import?<UIKit/UIKit.h>??
  11. ??
  12. @interface?TextField?:?UITextField??
  13. ??
  14. @property?(nonatomic,?assign)?CGFloat?dx;??
  15. @property?(nonatomic,?assign)?CGFloat?dy;??
  16. ??
  17. @end??


?


?

  1. .m??
  2. //??
  3. //??TextField.m??
  4. //??TTShow??
  5. //??
  6. //??Created?by?twb?on?13-9-10.??
  7. //??Copyright?(c)?2013年?twb.?All?rights?reserved.??
  8. //??
  9. ??
  10. #import?"TextField.h"??
  11. ??
  12. #define?kTextFieldPaddingWidth??(10.0f)??
  13. #define?kTextFieldPaddingHeight?(10.0f)??
  14. ??
  15. @implementation?TextField??
  16. ??
  17. -?(id)initWithFrame:(CGRect)frame??
  18. {??
  19. ????self?=?[super?initWithFrame:frame];??
  20. ????if?(self)?{??
  21. ????????//?Initialization?code??
  22. ????}??
  23. ????return?self;??
  24. }??
  25. ??
  26. -?(CGRect)textRectForBounds:(CGRect)bounds??
  27. {??
  28. ????return?CGRectInset(bounds,??
  29. ???????????????????????self.dx?==?0.0f???kTextFieldPaddingWidth?:?self.dx,??
  30. ???????????????????????self.dy?==?0.0f???kTextFieldPaddingHeight?:?self.dy);??
  31. }??
  32. ??
  33. -?(CGRect)editingRectForBounds:(CGRect)bounds??
  34. {??
  35. ????return?CGRectInset(bounds,??
  36. ???????????????????????self.dx?==?0.0f???kTextFieldPaddingWidth?:?self.dx,??
  37. ???????????????????????self.dy?==?0.0f???kTextFieldPaddingHeight?:?self.dy);??
  38. }??
  39. ??
  40. -?(void)setDx:(CGFloat)dx??
  41. {??
  42. ????_dx?=?dx;??
  43. ????[self?setNeedsDisplay];??
  44. }??
  45. ??
  46. -?(void)setDy:(CGFloat)dy??
  47. {??
  48. ????_dy?=?dy;??
  49. ????[self?setNeedsDisplay];??
  50. }??
  51. ??
  52. /*?
  53. //?Only?override?drawRect:?if?you?perform?custom?drawing.?
  54. //?An?empty?implementation?adversely?affects?performance?during?animation.?
  55. -?(void)drawRect:(CGRect)rect?
  56. {?
  57. ????//?Drawing?code?
  58. }?
  59. */??
  60. ??
  61. @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"];

?

iOS UITextField 设置内边距

标签:

原文地址:http://www.cnblogs.com/allen123/p/4589146.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!