前言: 意为打造类似原生控件样式的控件, 类似于UIAlertViewController
Cocoa pods支持:
- Add
pod 'XTAlertViewController', '~> 1.0.1'
to your Podfile - Run
pod install
or pod update –no-repo-update - import <XTAlertView.h>
优点在于:
- iOS 7.0 之后可用
- 可添加Header图片(且可选)
- 同时使用动画的方式, 交互更好, 高度自定义, 可以修改成你想要的样式.
- 使用简单
- 点击事件, 使用代理实现
- 低耦合, 采用推出新的控制器的方式
如何使用, 请看示例代码
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
// 初始化 XTAlertViewController *xt = [[XTAlertViewController alloc] init]; // Give a picture name // Give a picture's height // Give a btn's title array // Give a title // Give a describtion // Give a style two btn | double btn // example 1: 不采用Header图片, 可以图片参数为空, 或者高度为0, // 分别左右两个按钮的样式 style:AlterDefault(是一个枚举类型) [xt initWithImage:@"summerxx" imageHeight:0 title:@"This is an introduction" btnTitles:@[@"Cancel", @"Determine"] des:@"A simple and easy to use more version using the controls Copyright © 2016年 夏天然后. All rights reserved." style:AlertDefault]; // 推出新的控制器 [self presentViewController:xt animated:YES completion:^{ }]; // example 2: 多按钮 采用Header图片的样式. [xt initWithImage:@"summerxx" imageHeight:200 title:@"This is an introduction" btnTitles:@[@"Cancel", @"Determine", @"summerxx"] des:@"A simple and easy to use more version using the controls Copyright © 2016年 夏天然后. All rights reserved." style:AlertDouble]; // present VC [self presentViewController:xt animated:YES completion:^{ }]; |
签订协议, 指定代理人
1 2 3 4 |
// Signed an delegate @interface ViewController ()<XTAlertControllerDelegate> // xt.delegate = self; |
实现协议方法
- AlterDefault 样式 buttonIndex – index 0 | 1
- AlterDoyble 样式 buttonIndex – index 0 | 1 | 2 …
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
- (void)xt_alertViewControllerClickIndex:(NSInteger)buttonIndex { switch (buttonIndex) { case 0: NSLog(@"0"); NSLog(@"Cancel"); break; case 1: NSLog(@"1"); NSLog(@"Determine"); break; case 2: NSLog(@"2"); NSLog(@"summerxx"); break; default: break; } } |
程序示例入口:
https://github.com/summerxx27/XTAlertViewController
下载示例工程就可以, 或者使用Cocoapods体验
如果您觉得有帮助, 请给我点个赞或者关注我, 谢谢~
End 文/夏天然后