美文网首页iOS进阶动画iOS项目开发应用
iOS7兼容自定义带动画的AlertViewController

iOS7兼容自定义带动画的AlertViewController

作者: 夏天然后 | 来源:发表于2016-09-01 16:13 被阅读1347次

意为打造类似原生控件样式的控件, 类似于UIAlertViewController
优点在于:

  • iOS 7.0 之后可用
  • 可添加Header图片(且可选)
  • 同时使用动画的方式, 交互更好, 高度自定义, 可以修改成你想要的样式.
  • 使用简单
  • 点击事件, 使用代理实现
  • 低耦合, 采用推出新的控制器的方式

如何使用, 请看示例代码

        // 初始化
        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:^{

        }];

签订协议, 指定代理人

    // Signed an delegate
    @interface ViewController ()<XTAlertControllerDelegate>
    // 
    xt.delegate = self;

实现协议方法

  • AlterDefault 样式 buttonIndex - index 0 | 1
  • AlterDoyble 样式 buttonIndex - index 0 | 1 | 2 ...
- (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;
    }
}

这是一个支持Cocoapods的小工具(上传遇到了很多问题, 心好累~)

// 1.1.0.beta.1 能够搜到~
Add `pod 'XTAlertViewController', '~> 1.0.1'` to your Podfile
Run `pod install` or pod update --no-repo-update
import 

程序示例入口 https://github.com/summerxx27/XTAlertViewController

感谢简书提供平台记录学习点滴
如果您觉得有帮助, 请给我点个赞或者关注我, 谢谢~

效果图
---------------------------------------

走心文章, 值得点赞 ---文/夏天然后
微博-点我@夏天是个大人了 || QQ群: 498143780

End 文/夏天然后

可以关注我的订阅号 [夏天然后 ID: xt1005430006]

夏天然后

相关文章

网友评论

本文标题:iOS7兼容自定义带动画的AlertViewController

本文链接:https://www.haomeiwen.com/subject/mwjzsttx.html