insertSubview: belowSubview:
在主视图self.view 中 ,在self.tableView 下面(belowSubview
)或上面(aboveSubview
)插入一个toolView,
[self.view insertSubview:toolView belowSubview:self.tableView];
[self.view insertSubview:toolView aboveSubview:self.tableView];
示例:
在一个 view前插入另一个view,

-
代码:主视图backView,先在其上addSubview一个UITextField,在向UITextField之前插入一个红色的textBackView
[backView insertSubview:textBackView belowSubview:self.textField];
UIView *backView = [[UIView alloc] init];
backView.backgroundColor = [UIColor clearColor];
backView.layer.masksToBounds = YES;
backView.layer.cornerRadius = [UIScreen mainScreen].bounds.size.width/375*10;
[self addSubview:backView];
[backView makeConstraints:^(MASConstraintMaker *make) {
make.centerY.mas_equalTo(self.mas_centerY).offset(-[UIScreen mainScreen].bounds.size.width/375*20);
make.centerX.equalTo(self);
make.width.mas_equalTo([UIScreen mainScreen].bounds.size.width/375*371);
make.height.mas_equalTo([UIScreen mainScreen].bounds.size.width/375*195);
}];
UIImageView *bottomImgView = [[UIImageView alloc] init];
bottomImgView.image = [UIImage imageNamed:@"new_RTestIDBack_icon"];
[backView addSubview:bottomImgView];
[bottomImgView makeConstraints:^(MASConstraintMaker *make) {
make.edges.equalTo(backView);
}];
_textField = [[UITextField alloc] init];
_textField.autocorrectionType = UITextAutocorrectionTypeNo;
_textField.returnKeyType = UIReturnKeyDone;
_textField.backgroundColor = RGBA(245, 245, 251, 1);
_textField.placeholder = @"请输入考试唯一ID";
_textField.textAlignment = NSTextAlignmentLeft;
_textField.font = [UIFont systemFontOfSize:[UIScreen mainScreen].bounds.size.width/375*17 weight:UIFontWeightMedium];
_textField.delegate = self;
_textField.clearButtonMode = UITextFieldViewModeAlways;
self.textField.layer.masksToBounds = YES;
self.textField.layer.cornerRadius = [UIScreen mainScreen].bounds.size.width/375*5;
[backView addSubview:self.textField];
[self.textField makeConstraints:^(MASConstraintMaker *make) {
make.center.equalTo(bottomImgView);
make.width.mas_equalTo([UIScreen mainScreen].bounds.size.width/375*235);
make.height.mas_equalTo([UIScreen mainScreen].bounds.size.width/375*40);
}];
UIView *textBackView = [[UIView alloc] init];
textBackView.backgroundColor = rgba(245, 245, 251, 1);
textBackView.backgroundColor = [UIColor redColor];
textBackView.layer.masksToBounds = YES;
textBackView.layer.cornerRadius = [UIScreen mainScreen].bounds.size.width/375*5;
[backView insertSubview:textBackView belowSubview:self.textField];
[textBackView makeConstraints:^(MASConstraintMaker *make) {
make.center.height.equalTo(self.textField);
make.width.mas_equalTo([UIScreen mainScreen].bounds.size.width/375*255);
}];
网友评论