_leftImageView = [[UIImageView alloc] init];
UIView*leftView = [[UIViewalloc]init];
leftView.frame=CGRectMake(0,0,30,30);
_leftImageView.image = [UIImage imageNamed:@"dm_search_left_icon"];
_leftImageView.backgroundColor = [UIColor clearColor];
[leftViewaddSubview:_leftImageView];
[_leftImageView mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(leftView.mas_left).with.offset(10);
make.centerY.equalTo(leftView.mas_centerY).with.offset(0);
make.size.mas_equalTo(CGSizeMake(18,18));
}];
UIImage*backgroudImage = [UIImageimageNamed:@"dtww_reservation_input_bg"];
_textField = [[UITextField alloc] init];
_textField.font = [UIFont systemFontOfSize:12];
_textField.leftViewMode = UITextFieldViewModeAlways;
_textField.clearButtonMode = UITextFieldViewModeWhileEditing;
_textField.returnKeyType = UIReturnKeySearch;
_textField.delegate = self;
[self addSubview:_textField];
调试发现是leftView覆盖了textfield 尝试更新leftview的约束,发现_textField.superview拿到的值是nil,暂时把leftView放在textfiled左侧
if(@available(iOS13.0, *)) {
UIImageView*bgView = [[UIImageViewalloc]init];
bgView.image= backgroudImage;
[selfaddSubview:bgView];
[bgViewmas_makeConstraints:^(MASConstraintMaker*make) {
make.edges.equalTo(ws).insets(UIEdgeInsetsZero);
}];
[selfaddSubview:leftView];
[leftViewmas_makeConstraints:^(MASConstraintMaker*make) {
make.left.equalTo(ws.mas_left).with.offset(0);
make.centerY.equalTo(ws.mas_centerY);
make.size.mas_equalTo(CGSizeMake(30,30));
}];
[_textField mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(leftView.mas_right).offset(0);
make.top.bottom.right.equalTo(ws);
}];
}else{
_textField.leftView= leftView;
[_textFieldsetBackground:backgroudImage];
[_textField mas_makeConstraints:^(MASConstraintMaker *make) {
make.edges.equalTo(ws).with.insets(UIEdgeInsetsZero);
}];
}
网友评论