是否可以对UITextField的clearButton进行对齐?可以对齐UITextField的clearButton
我已经添加按钮,文本字段programaticly:
_usernameTextField.clearButtonMode = UITextFieldViewModeWhileEditing;
但它位于低一点,然后在文本字段的中心。
我怎样才能解决这个问题?
是否可以对UITextField的clearButton进行对齐?可以对齐UITextField的clearButton
我已经添加按钮,文本字段programaticly:
_usernameTextField.clearButtonMode = UITextFieldViewModeWhileEditing;
但它位于低一点,然后在文本字段的中心。
我怎样才能解决这个问题?
您可以扩展UITextField
并覆盖clearButtonRectForBounds:
并提供自定义矩形。
您是否尝试过字段本身的contentVerticalAlignment属性?
usernameField.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
最初引用:Why doesn't the clear button aligned with the text in a UITextField?
它没有做任何事情。按钮留在同一个地方 – Luda 2013-02-14 08:26:02
最后我划分子类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
什么垂直对齐? – 2013-02-13 16:27:38
怎么样?有没有这方面的财产? – Luda 2013-02-13 16:28:58
它没有做任何事情。按钮留在同一个地方。 – Luda 2013-02-13 16:34:00