技巧性分享,基于原生UIAlertController,扩展出可以定义内容区的UIAlertController弹框。几行代码,看懂即可。开发者巧用换行符:\n
。
UIAlertController *alert = [UIAlertController alertControllerWithTitle:
@"UIAlertController\n\n\n\n\n"
message:@""
preferredStyle:(UIAlertControllerStyleAlert)];
UIView *contentView = [UIView new];
contentView.backgroundColor = [UIColor groupTableViewBackgroundColor];
[alert.view addSubview:contentView];
[contentView mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(alert.view.mas_left).mas_offset(10);
make.right.mas_equalTo(alert.view.mas_right).mas_offset(-10);
make.top.mas_equalTo(alert.view.mas_top).mas_offset(50);
make.height.mas_equalTo(95);
}];
[alert addAction:[UIAlertAction actionWithTitle:@"确认"
style:(UIAlertActionStyleDefault)
handler:^(UIAlertAction * _Nonnull action) {
}]];
[self presentViewController:alert animated:YES completion:nil];