zoukankan      html  css  js  c++  java
  • iOS UITextField 设置内边距

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

     
  • 相关阅读:
    Linux .下Apache的安装
    从程序员到项目经理:项目管理三大目标
    linux下mysql安装
    Linux学习之常用命令
    转载:struts2拦截器
    el自定义函数库
    JAVA正则表达式小结
    JSP自定义标记
    JAVA动态代理(JDK和CGLIB)
    JAVA反射机制
  • 原文地址:https://www.cnblogs.com/allen123/p/4589146.html
Copyright © 2011-2022 走看看