v0.9.5
支持 iOS7及以上版本
从 iOS7 开始,UIAlertView 中不可用 addSubview。这个类的视图层次结构是私有的,不能修改。
作为解决方案,这个类创建了一个iOS样式的对话框,您可以用任何 UIView 或按钮扩展。动画和外观也复制了,不需要图像或其他资源。
只需将以下文件添加到您的项目中即可:
或者使用 Cocoapods
pod 'CustomIOSAlertView', '~> 0.9.5'
修复了 iOS8 的旋转问题
已从类名中移除了 7。现在只需使用 CustomIOSAlertView,例如:[[CustomIOSAlertView alloc] init];
initWithParentView 方法现已弃用。请使用 init 方法,您完全不需要传递父视图。如果在您的环境中 init 方法不起作用,请在这里留下注释或创建一个问题。
创建 UIView 对象 changed
CustomIOSAlertView *alertView = [[CustomIOSAlertView alloc] init];
将自定义内容添加到警报视图(可选)
UIView *customView ..;
[alertView setContainerView:customView];
显示对话框
[alertView show];
关闭对话框
[alertView close];
要添加更多按钮,传递一个标题列表
[alertView setButtonTitles:[NSMutableArray arrayWithObjects:@"Button1", @"Button2", @"Button3", nil]];
通过传递 nil 可以移除所有按钮
[alertView setButtonTitles:NULL];
可以开启或关闭 iOS7 的景深效果
[alertView setUseMotionEffects:TRUE];
使用自定义代理处理按钮点击
首先,设置代理
[alertView setDelegate:self];
然后添加代理方法
- (void)customIOS7dialogButtonTouchUpInside: (CustomIOSAlertView *)alertView clickedButtonAtIndex: (NSInteger)buttonIndex
{
NSLog(@"Button at position %d is clicked on alertView %d.", buttonIndex, [alertView tag]);
}
使用代码块处理按钮点击
[alertView setOnButtonTouchUpInside:^(CustomIOSAlertView *alertView, int buttonIndex) {
NSLog(@"Block: Button at position %d is clicked on alertView %d.", buttonIndex, [alertView tag]);
[alertView close];
}];
您还可以通过以下方式禁用所有其他代理:
[alertView setDelegate:self];
这是一个非常快速的实现,有一些事情还没有完成
添加更多按钮:它们的外观与 iOS7 不完全匹配
旋转:在键盘打开时旋转错误
MIT。请阅读LICENSE.md 获取更多信息。
请访问Appwoodoo 体验推送通知和远程应用程序控制服务。开源SDK可在Github上找到:github.com/appwoodoo。
更多免费资源请访问Github,供网络开发者使用。
项目更新 邮件列表
Richard Dancsi
www.wimagguc.com
twitter: @wimagguc
linkedin: linkedin.com/in/richarddancsi