iOS   发布时间:2022-03-30  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了ios – UIAlertController和UIAlertControllerStyleActionSheet自定义大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我正在尝试使用样式UIAlertControllerStyleActionSheet(以前的UIActionSheet)创建一个自定义UIAlertController,我遇到了很多麻烦来简单地自定义它.我希望我的UIAlertAction在左侧包含图像并减小按钮大小.

我知道这是可行的:

ios – UIAlertController和UIAlertControllerStyleActionSheet自定义

(这正是我正在寻找的)

搜索了几个小时,但我在互联网上找不到任何可以帮助我完成这个简单任务的tut.另外,由于UIActionSheet自IOS 9以来已被弃用,因此无论何时我尝试找到解决方案,它都不再可用.另外,我读到UIAlertController不打算被子类化……

有谁知道如何轻松定制我的警报?
我是否必须将uIView子类化为自己的警报表?

解决方法

解决方案使用私有API /属性.根据我的研究和经验,这是我知道你可以自定义UIAlertController的唯一方法.如果你看一下公共标题,UIAlertContoller几乎没有定制空间.但是,在iOS 8中启动UIAlertController之后,这个解决方案通常在开发人员中使用.您可以完全依赖Github的依赖关系.我希望我的回答可以解决你的问题.
我相信这就是你要找的东西,结果如下:

首先,您必须创建一个UIAlertController

UIAlertController *alertVC = [UIAlertController alertControllerWithtitle:@"Alert title" message:@"" preferredStyle:UIAlertControllerStyleActionSheet];

自定义字体!即使只是某些角色.

NSMutableAttributedString *hogan = [[NSMutableAttributedString alloc] initWithString:@"PresenTing the great... StackOverFlow!"];
[hogan addAttribute:NSFontAttributENAME value:[UIFont systemFontOfSize:30.0] range:NsmakeRange(24,11)];
[alertVC @R_489_6938@ue:hogan forKey:@"attributedtitle"];

现在,让我们创一个UIAlertAction,您可以在其中添加动作处理程序并添加图标.

UIAlertAction *button = [UIAlertAction actionWithtitle:@"First Button"
                                                 style:UIAlertActionStyleDefault
                                               handler:^(UIAlertAction *action){
                                                   //add code to make something happen once tapped
                                               }];
UIAlertAction *button2 = [UIAlertAction actionWithtitle:@"Second Button"
                                                 style:UIAlertActionStyleDefault
                                               handler:^(UIAlertAction *action){
                                                   //add code to make something happen once tapped
                                               }];

在这里,您将图标添加到AlertAction.对我来说,你必须指定UIImageRenderingModeAlwaysOriginal

[button @R_489_6938@ue:[[UIImage imagenamed:@"image.png"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] forKey:@"image"];

[alertVC addAction:button2];
[alertVC addAction:button];

记得要呈现ViewController

[self presentViewController:alertVC animated:YES completion:nil];

ios – UIAlertController和UIAlertControllerStyleActionSheet自定义

大佬总结

以上是大佬教程为你收集整理的ios – UIAlertController和UIAlertControllerStyleActionSheet自定义全部内容,希望文章能够帮你解决ios – UIAlertController和UIAlertControllerStyleActionSheet自定义所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。
标签:ios自定义