CustomIOSAlertView 0.9.5

CustomIOSAlertView 0.9.5

测试已测试
语言语言 Obj-CObjective C
许可证 MIT
发布上次发布2016年9月

Richard Dancsi维护。




Custom iOS AlertView

v0.9.5

支持 iOS7及以上版本

从 iOS7 开始,UIAlertView 中不可用 addSubview。这个类的视图层次结构是私有的,不能修改。

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

A demo screen

安装

只需将以下文件添加到您的项目中即可:

  • CustomIOSAlertView.h
  • CustomIOSAlertView.m

或者使用 Cocoapods

pod 'CustomIOSAlertView', '~> 0.9.5'

变更记录

  • 修复了 iOS8 的旋转问题

  • 已从类名中移除了 7。现在只需使用 CustomIOSAlertView,例如:[[CustomIOSAlertView alloc] init];

  • initWithParentView 方法现已弃用。请使用 init 方法,您完全不需要传递父视图。如果在您的环境中 init 方法不起作用,请在这里留下注释或创建一个问题。

快速入门指南

  1. 创建 UIView 对象 changed

    CustomIOSAlertView *alertView = [[CustomIOSAlertView alloc] init];
    
  2. 将自定义内容添加到警报视图(可选)

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

    [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 不完全匹配

  • 旋转:在键盘打开时旋转错误

特别感谢

  • @tamasdancsi 对初始代码的支持
  • @dingosky 因其在视差效果代码上的工作
  • @raspu 因其在协议代理、iOS6支持以及onButtonClick块上的工作
  • @sbandol 因其在将AlertView添加为层次结构中最高视图的设想
  • @scorpiozj 因其在旋转代码上的工作
  • @kwent 因其增加性能优化的工作
  • @thomasaw 因其对已弃用的initWithParentview的重构
  • @yiboyu 因其多行按钮修复
  • @logicxd 因其关闭触摸外部区域的代码

许可证

MIT。请阅读LICENSE.md 获取更多信息。

其他项目

请访问Appwoodoo 体验推送通知和远程应用程序控制服务。开源SDK可在Github上找到:github.com/appwoodoo

更多免费资源请访问Github,供网络开发者使用。

项目更新 邮件列表

介绍

Richard Dancsi
www.wimagguc.com

twitter: @wimagguc
linkedin: linkedin.com/in/richarddancsi