自定义UIAlertController-不看的后悔

2019-12-13  本文已影响0人  哈哈西

技巧性分享,基于原生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
上一篇 下一篇

猜你喜欢

热点阅读