ISAlertView 0.2

ISAlertView 0.2

测试已测试
语言语言 Obj-CObjective C
许可证 MIT
发布日期上次发布2015年5月

Ilya Stepanov维护。



  • 作者
  • Ilya Stepanov

v0.2

在iOS7中,UIAlertView已经不再有addSubview方法。这个类的视图层次结构是私有的并且不得被修改。

作为解决方案,这个类创建了一个iOS7风格的对话框,您可以扩展它以包含任何UIView或按钮。动画和外观也一同复制,不需要任何图像或其他资源。

A demo screen

安装

有2种方法可以将ISAlertView添加到您的项目

2. 手动安装

将以下文件添加到您的项目中

  • ISAlertView.h
  • ISAlertView.m

快速入门指南

  1. 创建UIView对象

    ISAlertView *alertView = [[ISAlertView alloc] init];
    
  2. 将一些自定义内容添加到alert视图(可选)

    UIView *customView ..;
    
    [alertView setContainerView:customView];
    
  3. 显示对话框

    [alertView show];
    

更多功能

  • 关闭对话框

    [alertView close];
    
  • 要添加更多按钮,传递一个包含标题的列表

    [alertView setButtonTitles:[NSMutableArray arrayWithObjects:@"Button1", @"Button2", @"Button3", nil]];
    
  • 通过传递nil可以移除所有按钮

    [alertView setButtonTitles:NULL];
    
  • 您可以在alert视图中启用或禁用iOS7的视差效果

    [alertView setUseMotionEffects:TRUE];
    
  • 使用自定义代理处理按钮点击

    首先设置代理

    [alertView setDelegate:self];
    

    然后添加代理方法

    - (void)customIOS7dialogButtonTouchUpInside:(ISAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
    {
        NSLog(@"Button at position %d is clicked on alertView %d.", buttonIndex, [alertView tag]);
    }
    
  • 使用代码块处理按钮点击

    [alertView setOnButtonTouchUpInside:^(ISAlertView *alertView, int buttonIndex) {
        NSLog(@"Block: Button at position %d is clicked on alertView %d.", buttonIndex, [alertView tag]);
        [alertView close];
    }];
    

    您也可以通过以下方式禁用所有其他代理:

    [alertView setDelegate:self];
    

致谢

此项目是Richard Dancsi创建的Custom iOS7 AlertView的分支。

许可证

查看LICENSE文件。