自定义UIAlertController-不看的后悔

技巧性分享,基于原生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];
image
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。