[翻译] MSAlertController
MSAlertController
You can use AlertController in iOS7!! 你可以在iOS中使用AlertController了
MSAlertController has same feature at UIAlertViewController. MSAlertController有着与UIAlertViewController一样的特性
Alert ActionSheetIn addtion, customize font, font size and font color.
另外,他还可以自定义字体,以及字体颜色。
Usage - 使用
To run the example project, clone the repo, and run pod install from the Example directory first.
为了运行这个应用程序,复制repo,然后运行pod进行安装即可。
For Alert 用于Alert
Set MSAlertControllerStyleAlert to preferredStyle.
将MSAlertControllerStyleAlert设置到预定样式。
MSAlertController *alertController = [MSAlertController alertControllerWithTitle:@"MSAlertController" message:@"This is MSAlertController." preferredStyle:MSAlertControllerStyleAlert]; MSAlertAction *action = [MSAlertAction actionWithTitle:@"Cancel" style:MSAlertActionStyleCancel handler:^(MSAlertAction *action) { //Write a code for this action. [alertController addAction:action]; MSAlertAction *action2 = [MSAlertAction actionWithTitle:@"Destructive" style:MSAlertActionStyleDestructive handler:^(MSAlertAction *action) { //Write a code for this action. [alertController addAction:action2]; MSAlertAction *action3 = [MSAlertAction actionWithTitle:@"Default" style:MSAlertActionStyleDefault handler:^(MSAlertAction *action) { //Write a code for this action. [alertController addAction:action3]; [self presentViewController:alertController animated:YES completion:nil];
For Action Sheet 用于Action Sheet
Set MSAlertControllerStyleActionSheet to preferredStyle.
将MSAlertControllerStyleActionSheet设定成预定样式。
MSAlertController *alertController = [MSAlertController alertControllerWithTitle:@"MSAlertController" message:@"This is MSAlertController." preferredStyle:MSAlertControllerStyleActionSheet]; MSAlertAction *action = [MSAlertAction actionWithTitle:@"Cancel" style:MSAlertActionStyleCancel handler:^(MSAlertAction *action) { //Write a code for this action. [alertController addAction:action]; MSAlertAction *action2 = [MSAlertAction actionWithTitle:@"Destructive" style:MSAlertActionStyleDestructive handler:^(MSAlertAction *action) { //Write a code for this action. [alertController addAction:action2]; MSAlertAction *action3 = [MSAlertAction actionWithTitle:@"Default" style:MSAlertActionStyleDefault handler:^(MSAlertAction *action) { //Write a code for this action. [alertController addAction:action3]; [self presentViewController:alertController animated:YES completion:nil];
Customization - 定制
For Action Controller - 对于Action Controller
@property (strong, nonatomic) UIColor *titleColor; @property (strong, nonatomic) UIFont *titleFont; @property (strong, nonatomic) UIColor *messageColor; @property (strong, nonatomic) UIFont *messageFont; @property (assign, nonatomic) BOOL enabledBlurEffect; @property (strong, nonatomic) UIColor *backgroundColor; @property (assign, nonatomic) CGFloat alpha; @property (strong, nonatomic) UIColor *alertBackgroundColor; @property (strong, nonatomic) UIColor *separatorColor;
MSAlertController *alertController = [MSAlertController alertControllerWithTitle:@"MSAlertController" message:@"This is MSAlertController." preferredStyle:MSAlertControllerStyleAlert]; alertController.titleColor = [UIColor blueColor]; alertController.titleFont = [UIFont fontWithName:@"Baskerville-BoldItalic" size:20.0f]; alertController.messageColor = [UIColor greenColor]; alertController.messageFont = [UIFont fontWithName:@"Baskerville-BoldItalic" size:18.0f];
For Action - 对于Action
@property (strong, nonatomic) UIColor *titleColor; @property (strong, nonatomic) UIFont *font; @property (strong, nonatomic) UIColor *normalColor; @property (strong, nonatomic) UIColor *highlightedColor;
MSAlertAction *action = [MSAlertAction actionWithTitle:@"Cancel" style:MSAlertActionStyleCancel handler:^(MSAlertAction *action) { //Write a code for this action. action.titleColor = [UIColor redColor]; action.font = [UIFont fontWithName:@"Baskerville-BoldItalic" size:18.0f]; [alertController addAction:action];
Combination - 组合样式
MSAlertController *alertController = [MSAlertController alertControllerWithTitle:@"MSAlertController" message:@"This is MSAlertController." preferredStyle:MSAlertControllerStyleAlert]; alertController.alertBackgroundColor = [UIColor lightGrayColor]; alertController.backgroundColor = [UIColor blueColor]; alertController.alpha = 0.3f; alertController.separatorColor = [UIColor redColor]; MSAlertAction *action = [MSAlertAction actionWithTitle:@"Cancel" style:MSAlertActionStyleCancel handler:^(MSAlertAction *action) { NSLog(@"Cancel action tapped %@", action); action.normalColor = [UIColor blackColor]; action.highlightedColor = [UIColor yellowColor]; [alertController addAction:action]; MSAlertAction *action2 = [MSAlertAction actionWithTitle:@"Destructive" style:MSAlertActionStyleDestructive handler:^(MSAlertAction *action) { NSLog(@"Destructive action tapped %@", action); [alertController addAction:action2]; MSAlertAction *action3 = [MSAlertAction actionWithTitle:@"Default" style:MSAlertActionStyleDefault handler:^(MSAlertAction *action) { NSLog(@"Default action tapped %@", action); action3.normalColor = [UIColor darkGrayColor]; action3.highlightedColor = [UIColor whiteColor]; [alertController addAction:action3]; [alertController addTextFieldWithConfigurationHandler:nil]; [self presentViewController:alertController animated:YES completion:nil];
Action Sheet is compatible with same customization.
Action Sheet可以自由定制。
Requirements - 需要的环境
iOS 7.0 and greater iOS7.0或者更高 ARC ARC QuartzCore.framework QuartzCore框架Installation - 安装
MSAlertController is available through CocoaPods. To install it, simply add the following line to your Podfile:
CocoaPods中已经可以添加MSAlertController了,要安装他,简单执行下面一句话即可:
pod "MSAlertController"
相关文章
- Analyzing the Performance of an Anycast CDN(含论文谷歌翻译,人工补正)
- [翻译] Overleaf 中的语法检查 – Spell check language
- 爬虫案例-实现翻译功能
- 【阅读】A Comprehensive Survey on Electronic Design Automation and Graph Neural Networks——EDA+GNN综述翻译
- 继谷歌翻译第二次无法使用,如何使用平替谷歌翻译
- fizz buzz 翻译_thefizzbuzz中文翻译
- 【翻译】图像到Base64字符串转换
- 苹果Mac电脑超好用的翻译软件合集
- 在浏览器中直接翻译 WordPress 主题和插件
- [图]Vivaldi 4.0重大版本更新发布:引入翻译、电子邮件等诸多功能
- 翻译Linux命令:精通中文翻译(linux命令中文)
- 《软件架构》翻译邀请
- MySQL开启新时代之门(mysql翻译)
- asp.netGoogle的translate工具翻译API