YWAlertView 1.3.6

YWAlertView 1.3.6

YWRouter 维护。



  • 作者
  • flyOfYW

YWAlertView

提示弹出框、选择弹出框、日期选择器、地址选择器、高效调用、高效扩展

  • 最新更新记录
  v1.3.0 YWAlertView中的YWAlertViewStyleActionSheet模式支持懒加载,支持动态修改title和message,高度自动变化
  v1.2.2 YWAlertView中的YWAlertViewStyleAlert模式支持懒加载,支持动态修改title和message,高度自动变化
  v1.2.1 新增地址选择器
  v1.0.0 新增日历选择器以及时间格式化以及时间戳相关工具类
  v0.1.0 新增弹框提示和弹框选择器

兼容性

  • iPhone和iPad
  • 横屏和竖屏
  • iOS 7以上

集成方法

  1. 将 YWAlertView 文件拖入项目,引入头文件

#import "YWAlertView.h"

  1. 使用 cocopod
   pod 'YWAlertView'

介绍

YWAlertView 目前提供五种模式:

> YWAlertViewStyleAlert
> YWAlertViewStyleActionSheet
> YWAlertViewStyleDatePicker ////datePicker默认在中间显示
> YWAlertViewStyleDatePicker2 //datePicker底部显示
> YWAlertViewStyleAddressPicker
  • 注意点:YWAlertView 并不是一个视图,可以把它看作是一个简单的工厂,通过它来管理配置生成不同的控件,因为它将陆续加入其他控件,如日历、地址等
* YWAlertViewStyleAlert 模式
  1. 默认情况下

    image

  2. 底部视图的按钮横向排列,类似于系统样式,当按钮较多时就会横向显示,而 YWAlertView 提供了三种模式:横向、纵向以及按钮之间有间距的横向,供开发者自由选择

    image image

  3. 没有底部视图的情况下(支持没有标题和消息的情况),可以选择行来显示关闭按钮,字体也可以修改

    image

  4. 主体视图支持自定义(默认显示文字)

    image

  5. 全局配置基本设置(色调、背景、字体大小、字号等),以解决每次弹框都要设置这些参数的烦恼

    image

  6. 其他情况,请结合示例代码
* YWAlertViewStyleActionSheet 的模式
  1. 默认情况下,与系统的 ActionSheet 没有任何差异

    image

  2. 没有标题的情况下,(支持字号以及字体等修改)

    image

  3. 没有取消(cancel)的情况

    image

  4. 其他情况,请结合示例代码
* YWAlertViewStyleDatePicker 的模式
  1. 年月日时分秒,位置显示在中间,按钮横排显示

    image

  2. 年月日时分,位置显示在中间,按钮竖排显示

    image

  3. 年月日,位置显示在底部

    image

  4. 其他情况,请结合示例代码
* YWAlertViewStyleAddressPicker 的模式
  1. 省市区显示

    image

  2. 省市显示

    image

  3. 其他情况,请结合示例代码

使用

  1. delegate回调
   id <YWAlertViewProtocol>alert = [YWAlertView alertViewWithTitle:@"温馨提示" message:@"Do any additional setup after loading the view" delegate:self preferredStyle:YWAlertViewStyleAlert footStyle:YWAlertPublicFootStyleDefalut bodyStyle:YWAlertPublicBodyStyleDefalut cancelButtonTitle:@"cancel" otherButtonTitles:@[@"Ok"]];
  [alert show];
  1. block回调
  id <YWAlertViewProtocol>alert = [YWAlertView alertViewWithTitle:@"温馨提示" message:@"Do any additional setup after loading the view,typically from a nib" preferredStyle:YWAlertViewStyleAlert footStyle:YWAlertPublicFootStyleDefalut bodyStyle:YWAlertPublicBodyStyleDefalut cancelButtonTitle:nil otherButtonTitles:nil handler:^(NSInteger buttonIndex, id  _Nullable value) {
      NSLog(@"block=当前点击--%zi",buttonIndex);
  }];
  [alert setMessageFontWithName:@"Bodoni Ornaments" size:15];
  [alert show];
  1. 全局配置基本参数

创建一个继承自NSObject的实体类,并遵循协议,实现其基本参数配置方法,在显示alert时使用该实体类的对象,如:

    id <YWAlertViewProtocol>alert = [YWAlertView alertViewWithTitle:@"温馨提示" message:@"主题配置颜色以及背景图" delegate:self preferredStyle:YWAlertViewStyleAlert footStyle:YWAlertPublicFootStyleDefalut bodyStyle:YWAlertPublicBodyStyleDefalut cancelButtonTitle:@"cancel" otherButtonTitles:@[@"Ok"]];
  [alert setTheme:[YWTheme new]];
  [alert showOnViewController];

该继承自NSObject的实体类的.m文件内容如下,按需实现相应的方法

@implementation YWTheme
- (UIColor *)alertCancelColor{
  return [UIColor redColor];
}
- (UIImage *)alertBackgroundView{
  return [UIImage imageNamed:@"105459445"];
}
- (CGFloat)alterBackgroundViewArticulation{
  return 0.5;
}
- (NSString *)alertMessageFontWithName{
  return @"AmericanTypewriter";
}
- (NSString *)alertTitleFontWithName{
  return @"Baskerville-SemiBoldItalic";
}
@end

  1. 懒加载
- (id<YWAlertViewProtocol>)ywAlert{
 if (!_ywAlert) {
     _ywAlert = [YWAlertView alertViewWithTitle:nil message:@"懒加载模式,我要重置message的信息,高度也要进行相关的变化哦" delegate:self preferredStyle:YWAlertViewStyleAlert footStyle:YWAlertPublicFootStyleDefalut bodyStyle:YWAlertPublicBodyStyleDefalut cancelButtonTitle:@"cancel" otherButtonTitles:@[@"Ok"]];
 }
 return _ywAlert;
}
- (void)alert_defalut_lazing{
//强转协议,调用私有方法 message 和title均支持修改
 [(id<YWAlertAlertViewProtocol>)self.ywAlert resetAlertMessage:@"懒加载模式,我要重置message的信息,高度也要进行相关的变化哦"];
 [(id<YWAlertAlertViewProtocol>)self.ywAlert resetAlertTitle:@"使用第一行的对象alter"];
 [self.ywAlert show];
}
```