iOS UITextField 设置内边距

http://blog.csdn.net/erica_sadun/article/details/9088181

1.inherit UITextField Class.

?

[cpp]?view plaincopy

  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??

?

?

[cpp]?view plaincopy

  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"];

?

时间: 2024-08-12 09:26:47

iOS UITextField 设置内边距的相关文章

iOS UITextField设置placeholder颜色

设置UITextField的placeholder颜色 UIColor *color = [UIColor blackColor]; textField.attributedPlaceholder = [[NSAttributedString alloc] initWithString:@"密码" attributes:@{NSForegroundColorAttributeName: color}]; iOS UITextField设置placeholder颜色

【Swift】UILabel 设置内边距

前言 对应一个曾经开发 Android 的人来说,没有这些基础属性简直令人发指,还是表喷这个,认真写代码 - - # 声明 欢迎转载,但请保留文章原始出处:) 博客园:http://www.cnblogs.com 农民伯伯: http://over140.cnblogs.com 正文 class UILabelPadding : UILabel { private var padding = UIEdgeInsetsZero @IBInspectable var paddingLeft: CGF

iOS UITextField 设置下底边

@interface ViewController () @end @implementation ViewController - (void)viewDidLoad { [super viewDidLoad]; UITextField *textField = [[UITextField alloc] initWithFrame:CGRectMake(30, 100, 160, 30)]; textField.text = @"设置textField下边框"; CALayer *b

可以简易设置文字内边距的EdgeInsetsLabel

最终效果: 源码: EdgeInsetsLabel.h 与 EdgeInsetsLabel.m // // EdgeInsetsLabel.h // EdgeInsetsLabel // // Created by YouXianMing on 14/10/27. // Copyright (c) 2014年 YouXianMing. All rights reserved. // #import <UIKit/UIKit.h> @interface EdgeInsetsLabel : UIL

xcode UIButton创建、监听按钮点击、自定义按钮 、状态 、内边距

代码创建 //创建UIButton UIButton * btnType=[[UIButton alloc]init]; //设置UIControlStateNormal状态下的文字颜色 [btnType setTitleColor:[UIColor blackColor] forState:UIControlStateNormal]; //设置字体大小 btnType.titleLabel.font=[UIFont systemFontOfSize:9.0]; //设置边框的宽度 btnTyp

web前端入门到实战:内边距属性、外边距属性

一.内边距属性 1.定义:边框和内容之间的距离就是内边距 2.分开写 padding-top:数字px: padding-left:数字px: padding-bottom:数字px: padding-right:数字px: 3.连写: padding:上 右 下 左: 4.注意点: (1)给标签设置内边距之后,标签占有的宽度和高度会发生变化 (2)内边距也会有背景颜色 web前端开发学习Q-q-u-n: ⑦⑧④-⑦⑧③-零①②,分享学习的方法和需要注意的小细节,不停更新最新的教程和学习方法(详

iOS 设置UILabel 的内边距

iOS 设置UILabel 的内边距 - (void)drawTextInRect:(CGRect)rect { UIEdgeInsets insets = {0, 5, 0, 5}; [super drawTextInRect:UIEdgeInsetsInsetRect(rect, insets)]; } 参考:http://stackoverflow.com/questions/3476646/uilabel-text-margin http://unmi.cc/uilable-uitext

iOS UIButton 设置图片文字垂直排列

在实际的iOS项目开发中,我们经常需要改变系统的控件的样式,自己定义一个,同样的当我们发现系统自带的某些方法不好使时,我们也会想到重写这个方法. 本文主要记录笔者设置UIButton图片文字垂直排列的方法,最终解决了在图片和文字垂直排列的情况下,如果文字长度变化会导致图片位置变动的问题,对 于此问题网上有比较多的做法,我就不多说了,在此记录这点细节仅为加深印象并方便以后查阅.如有纰漏还请见谅 方案一:通过调整按钮图片和文字的内边距 UIEdgeInsets typedef struct UIEd

iOS UITextField控件总结

iOS UITextField控件总结 先声明下面总结不是自己写的. //初始化textfield并设置位置及大小 UITextField *text = [[UITextField alloc]initWithFrame:CGRectMake(20, 20, 130, 30)]; //设置边框样式,只有设置了才会显示边框样式 text.borderStyle = UITextBorderStyleRoundedRect; typedef enum { UITextBorderStyleNone