iOS巅峰之textField缩近文本

应用原型图上的文本框会稍微右缩进空几个空格的,看起来还好看些,当UItextField上直接用的话,那个光标会紧贴着左框,有些些不好看

很简单,继承UITextfield,覆盖父类方法!

[cpp]  view plain  copy
  1. #import <UIKit/UIKit.h>  
  2.   
  3. @interface InsetsTextField : UITextField  
  4. - (CGRect)textRectForBounds:(CGRect)bounds;  
  5. - (CGRect)editingRectForBounds:(CGRect)bounds;  
  6. @end  

[cpp]  view plain  copy
  1. #import "InsetsTextField.h"  
  2.   
  3. @implementation InsetsTextField  
  4.   
  5. //控制文本所在的的位置,左右缩 10  
  6. - (CGRect)textRectForBounds:(CGRect)bounds {  
  7.     return CGRectInset( bounds , 10 , 0 );  
  8. }  
  9.   
  10. //控制编辑文本时所在的位置,左右缩 10  
  11. - (CGRect)editingRectForBounds:(CGRect)bounds {  
  12.     return CGRectInset( bounds , 10 , 0 );  
  13. }  
  14.   
  15. @end  

猜你喜欢

转载自blog.csdn.net/qw656567/article/details/52984347
今日推荐