我有一個UITextField
子類,其中我重寫了一些方法(請參閱下面的代碼)。問題是,當我輸入文本並且文本達到邊界時,它將不再顯示我輸入的內容。在調試模式下,我發現UIFieldEditor
比文本提交的要寬得多。UITextField文本不在左側滾動
這裏是UITextFiled子類代碼:
- (instancetype)init
{
self = [super init];
if (self) {
self.edgeInsets = UIEdgeInsetsMake(7, 0, 10, 15);
}
return self;
}
- (id)initWithFrame:(CGRect)frame{
self = [super initWithFrame:frame];
if (self) {
self.edgeInsets = UIEdgeInsetsMake(7, 0, 10, 15);
}
return self;
}
-(id)initWithCoder:(NSCoder *)aDecoder{
self = [super initWithCoder:aDecoder];
if(self){
self.edgeInsets = UIEdgeInsetsMake(7, 0, 10, 15);
}
return self;
}
- (CGRect)textRectForBounds:(CGRect)bounds {
return [super textRectForBounds:UIEdgeInsetsInsetRect(bounds, self.edgeInsets)];
}
- (CGRect)editingRectForBounds:(CGRect)bounds {
return [super editingRectForBounds:UIEdgeInsetsInsetRect(bounds, self.edgeInsets)];
}
這裏就是我使用這個類的代碼:
// alloc/init
_myTextField.delegate = self;
_myTextField.backgroundColor = [UIColor whiteColor];
_myTextField.layer.masksToBounds = YES;
_myTextField.layer.cornerRadius = 3.0;
_myTextField.returnKeyType = UIReturnKeyDone;
_myTextField.clearButtonMode = UITextFieldViewModeWhileEditing;
_myTextField.autocapitalizationType = UITextAutocapitalizationTypeWords;
_myTextField.autocorrectionType = UITextAutocorrectionTypeNo;
_myTextField.hidden = YES;
_tfButton = [UIButton buttonWithType:UIButtonTypeSystem];
[_tfButton setImage:[UIImage imageNamed:@"ic_edit"] forState:UIControlStateNormal];
[self fs_addSubview:_tfButton];
[_tfButton constrainWidth:22.];
[_tfButton setTintColor:[UIColor greenColor]];
[_tfButton constrainHeight:22.];
[_tfButton constrainToRightOfView:_myTextField margin:-25.0];
[_tfButton constrainEqualCenterYWithView:_myTextField offset:0.0];
[_tfButton setUserInteractionEnabled:NO];
UIView *leftView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 5, 5)];
_myTextField.leftView = leftView;
_myTextField.leftViewMode = UITextFieldViewModeAlways;
如何獲取文本左側滾動出時用戶在這個文本字段中輸入一個大字符串?
沒有工作... – user426132