2013-02-13 47 views
0

是否可以对UITextField的clearButton进行对齐?可以对齐UITextField的clearButton

我已经添加按钮,文本字段programaticly:

_usernameTextField.clearButtonMode = UITextFieldViewModeWhileEditing; 

但它位于低一点,然后在文本字段的中心。

enter image description here

我怎样才能解决这个问题?

+1

什么垂直对齐? – 2013-02-13 16:27:38

+0

怎么样?有没有这方面的财产? – Luda 2013-02-13 16:28:58

+0

它没有做任何事情。按钮留在同一个地方。 – Luda 2013-02-13 16:34:00

回答

0

最后我划分子类UITextField和覆盖功能。

.H

#import <UIKit/UIKit.h> 

@interface TVUITextFieldWithClearButton : UITextField 

@end 

.M

#import "TVUITextFieldWithClearButton.h" 

@implementation TVUITextFieldWithClearButton 

- (id)initWithFrame:(CGRect)frame 
{ 
    self = [super initWithFrame:frame]; 
    if (self) { 
     // Initialization code 
    } 
    return self; 
} 

- (void)awakeFromNib 
{ 
    self.clearButtonMode = UITextFieldViewModeWhileEditing; 
} 


- (CGRect)clearButtonRectForBounds:(CGRect)bounds 
{ 
    return CGRectMake(bounds.size.width/2-20 , bounds.origin.y-3, bounds.size.width, bounds.size.height); 
} 

@end