0x00 效果图
先看效果图~
1.展示图片的
2.展示自定义视图的
0x01 分类
想要添加视图,就要有足够的
空间
如何让系统给出
足够的空间呢?
当给 message
参数传递换行符时 \n
就会撑开
弹窗的高度
只要有足够多的 \n
就能撑开足够
高的高度
0x02 高度测量
使用了 6p
、 x
、 xr
进行测试
测试结果数据如下:
6p - scale: 3
\n - 31.67
\n\n - 47.67 (16)
\n\n\n - 63.67 (16)
x - scale: 3
\n - 31.67
\n\n - 47.67 (16)
\n\n\n - 63.67 (16)
xr - scale: 2
\n - 36
\n\n - 54 (18)
\n\n\n - 72 (18)
所以,根据外部传入的高度参数
可以计算出视图
所占的高度
CGFloat scale = [UIScreen mainScreen].scale;
CGFloat lineHeight = scale == 2 ? 18 : 16;
NSInteger count = ceilf(viewSize.height / lineHeight);
NSMutableString *msg = @"".mutableCopy;
for (NSInteger i = 0; i < count; i++) {
[msg appendString:@"\n"];
}
0x03 示例
展示图片的简单示例:
传入 图片名
和 size
即可
UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"请使用微信扫描二维码" image:@"qrxgame" imageSize:CGSizeMake(120, 120) preferredStyle:UIAlertControllerStyleAlert];
[alert addAction:[UIAlertAction actionWithTitle:@"好的" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
}]];
[self presentViewController:alert animated:YES completion:nil];
仓库地址:JHAlertController
0x04 我的小作品
欢迎体验我的作品之一:小编辑器-XCompiler
在线编辑器~小而巧
App Store
搜索即可~