iOS巅峰之textField缩近文本

来源:互联网 发布:sql必知必会第四版pdf 编辑:程序博客网 时间:2024/04/27 16:07

应用原型图上的文本框会稍微右缩进空几个空格的,看起来还好看些,当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  

0 0
原创粉丝点击