Git Product home page Git Product logo

leealert's Introduction

LEEAlert - 优雅的Alert ActionSheet

            Build Status 

演示

AlertDemo演示 ActionSheetDemo演示

特性

  • 链式语法 结构优雅
  • 支持alert类型与actionsheet类型
  • 默认样式为Apple风格 可自定义其样式
  • 支持自定义标题与内容 可动态调整其样式
  • 支持自定义视图添加 同时可设置位置类型等 自定义视图size改变时会自动适应.
  • 支持输入框添加 自动处理键盘相关的细节
  • 支持屏幕旋转适应 同时可自定义横竖屏最大宽度和高度
  • 支持自定义action添加 可动态调整其样式
  • 支持内部添加的功能项的间距范围设置等
  • 支持圆角设置 支持阴影效果设置
  • 支持队列和优先级 多个同时显示时根据优先级顺序排队弹出 添加到队列的如被高优先级覆盖 以后还会继续显示等.
  • 支持两种背景样式 1.半透明 (支持自定义透明度比例和颜色) 2.毛玻璃 (支持效果类型)
  • 支持自定义UIView动画方法
  • 支持自定义打开关闭动画样式(动画方向 渐变过渡 缩放过渡等)
  • 支持iOS13 Dark样式
  • 更多特性未来版本中将不断更新.

用法

概念

无论是Alert还是ActionSheet 这里我把它们内部的控件分为两类 一: 功能项类型 (Item) 二: 动作类型 (Action).

按照apple的风格设计 弹框分为上下两个部分 其中功能项的位置为 Header 既 头部, 而Action则在下部分.

功能项一般分为4种类型 1. 标题 2. 内容(也叫Message) 3.输入框 4.自定义的视图

Action一般分为3种类型 1. 默认类型 2. 销毁类型(Destructive) 3.取消类型(Cancel)

所以说 能添加的东西归根结底为两种 1. Item 2.Action  其余的都是一些设置等.

根据上面的概念 我来简单介绍一下API的结构:

所有添加的方法都是以 LeeAddItemLeeAddAction 两个方法为基础进行的扩展.

查看源码 可以发现 无论是 LeeAddTitle 还是 LeeAddTextField 最终都是通过 LeeAddItem 来实现的.

也就是说整个添加的结构是以他们两个展开的 , 这个仅作为了解即可.

Layout

Alert

    // 完整结构
    [LEEAlert alert].cofing.XXXXX.XXXXX.LeeShow();

ActionSheet

    // 完整结构
    [LEEAlert actionSheet].cofing.XXXXX.XXXXX.LeeShow();

默认基础功能添加

    [LEEAlert alert].config
    .LeeTitle(@"标题") 		// 添加一个标题 (默认样式)
    .LeeContent(@"内容")		// 添加一个标题 (默认样式)
    .LeeAddTextField(^(UITextField *textField) {	// 添加一个输入框 (自定义设置)
    	// textfield设置Block
    })
    .LeeCustomView(view)	// 添加自定义的视图
    .LeeAction(@"默认Action", ^{		//添加一个默认类型的Action (默认样式 字体颜色为蓝色)
    	// 点击事件Block
    })
    .LeeDestructiveAction(@"销毁Action", ^{	// 添加一个销毁类型的Action (默认样式 字体颜色为红色)
    	// 点击事件Block
    })
    .LeeCancelAction(@"取消Action", ^{	// 添加一个取消类型的Action (默认样式 alert中为粗体 actionsheet中为最下方独立)
    	// 点击事件Block
    })
    .LeeShow(); // 最后调用Show开始显示

自定义基础功能添加

    [LEEAlert alert].config
    .LeeAddTitle(^(UILabel *label) {
        
        // 自定义设置Block
        
        // 关于UILabel的设置这里不多说了
        
        label.text = @"标题";
        
        label.textColor = [UIColor redColor];
    })
    .LeeAddContent(^(UILabel *label) {
        
        // 自定义设置Block
        
        // 同标题一样
    })
    .LeeAddTextField(^(UITextField *textField) {
        
        // 自定义设置Block
        
        // 关于UITextField的设置你们都懂的 这里textField默认高度为40.0f 如果需要调整可直接设置frame 当然frame只有高度是有效的 其他的均无效
        
        textField.textColor = [UIColor redColor];
    })
    .LeeAddCustomView(^(LEECustomView *custom) {
        
        // 自定义设置Block
        
        // 设置视图对象
        custom.view = view;
        
        // 设置自定义视图的位置类型 (包括靠左 靠右 居中 , 默认为居中)
        custom.positionType = LEECustomViewPositionTypeLeft;
        
        // 设置是否自动适应宽度 (自适应宽度后 位置类型为居中)
        custom.isAutoWidth = YES;
    })
    .LeeAddAction(^(LEEAction *action) {
        
        // 自定义设置Block
        
        // 关于更多属性的设置 请查看'LEEAction'类 这里不过多演示了
        
        action.title = @"确认";
        
        action.titleColor = [UIColor blueColor];
    })
    .LeeShow();

自定义相关样式

    [LEEAlert alert].config
    .LeeCornerRadius(10.0f) 	//弹框圆角曲率
    .LeeShadowOpacity(0.35f) 	//弹框阴影的不透明度 0.0 -- 1.0
    .LeeHeaderColor([UIColor whiteColor]) 	//弹框背景颜色
    .LeeBackGroundColor([UIColor whiteColor])	 //屏幕背景颜色
    .LeeBackgroundStyleTranslucent(0.5f) 	//屏幕背景半透明样式 参数为透明度
    .LeeBackgroundStyleBlur(UIBlurEffectStyleDark)	 //屏幕背景毛玻璃样式 参数为模糊处理样式类型 `UIBlurEffectStyle`
    .LeeShow();

自定义最大宽高范围及相关间距

    [LEEAlert alert].config
    .LeeHeaderInsets(UIEdgeInsetsMake(10, 10, 10, 10)) 		// 头部内间距设置 等于内部项的范围
    .LeeMaxWidth(280.0f) // 设置最大宽度 (固定数值 横竖屏相同)
    .LeeMaxHeight(400.0f) // 设置最大高度 (固定数值 横竖屏相同)
    .LeeConfigMaxWidth(^CGFloat(LEEScreenOrientationType type, CGSize size) { 	// 设置最大宽度 (根据横竖屏类型进行设置 最大高度同理)
        
        if (type == LEEScreenOrientationTypeVertical) {
            
            // 竖屏类型
            
            return 280.0f;
        }
        
        if (type == LEEScreenOrientationTypeHorizontal) {
            
            // 横屏类型
            
            return 400.0f;
        }
        
        return 0.0f;
    })
    .LeeShow();
    

    [LEEAlert alert].config
    .LeeTitle(@"标题")
    .LeeItemInsets(UIEdgeInsetsMake(10, 0, 0, 0)) 	// 设置某一项的外边距范围 在哪一项后面 就是对哪一项进行设置
    .LeeContent(@"内容")
    .LeeItemInsets(UIEdgeInsetsMake(10, 0, 10, 0)) 	// 例如在设置标题后 紧接着添加一个LeeItemInsets() 就等于为这个标题设置了外边距范围  以此类推
    .LeeShow();
    
    /**
   	 LeeHeaderInsets 与 LeeItemInsets 决定了所添加的功能项的布局 可根据需求添加调整.
    */

自定义动画时长

    [LEEAlert alert].config
    .LeeOpenAnimationDuration(0.3f) // 设置打开动画时长 默认为0.3秒
    .LeeCloseAnimationDuration(0.2f) // 设置关闭动画时长 默认为0.2秒
    .LeeShow();

自定义动画样式

    [LEEAlert alert].config
    .LeeOpenAnimationStyle(LEEAnimationStyleOrientationTop | LEEAnimationStyleFade | LEEAnimationStyleZoom) //设置打开动画样式的方向为上 以及淡入效果和缩放效果.
    .LeeCloseAnimationStyle(LEEAnimationStyleOrientationBottom | LEEAnimationStyleFade | LEEAnimationStyleZoom) //设置关闭动画样式的方向为下 以及淡出效果和缩放效果.
    .LeeShow();

自定义动画方法设置

    [LEEAlert alert].config
    .LeeOpenAnimationConfig(^(void (^animatingBlock)(void), void (^animatedBlock)(void)) {
        
	// 可自定义UIView动画方法以及参数设置
	
        [UIView animateWithDuration:1.0f delay:0 usingSpringWithDamping:0.4 initialSpringVelocity:1 options:UIViewAnimationOptionAllowUserInteraction animations:^{
                    
            animatingBlock(); //调用动画中Block
                    
        } completion:^(BOOL finished) {
                    
            animatedBlock(); //调用动画结束Block
        }];
                
    })
    .LeeCloseAnimationConfig(^(void (^animatingBlock)(void), void (^animatedBlock)(void)) {
                
        [UIView animateWithDuration:0.5f delay:0 options:UIViewAnimationOptionCurveEaseOut animations:^{
                    
            animatingBlock();
                    
        } completion:^(BOOL finished) {
                    
            animatedBlock();
        }];
                
     })
    .LeeShow();

队列与优先级设置

    [LEEAlert alert].config
    .LeeQueue(YES)	// 设置添加到队列 默认不添加 (添加后 处于显示状态时 如果有新的弹框显示 会将它暂时隐藏 等新的弹框显示结束 再将其显示出来)
    .LeePriority(1) 	// 设置优先级 默认为0 按照优先级从高到低的顺序显示, 优先级相同时 优先显示最新的
    .LeeShow();
    /**
    	优先级和队列结合使用会将其特性融合 具体效果请运行demo自行调试体验
    */

其他设置

    [LEEAlert alert].config
    .LeePresentation([LEEPresentation windowLevel:UIWindowLevelAlert]) // 弹框window层级 默认UIWindowLevelAlert
    .LeeShouldAutorotate(YES) // 是否支持自动旋转 默认为NO
    .LeeSupportedInterfaceOrientations(UIInterfaceOrientationMaskAll) // 支持的旋转方向 默认为UIInterfaceOrientationMaskAll
    .LeeClickHeaderClose(YES) // 点击弹框进行关闭 默认为NO
    .LeeClickBackgroundClose(YES) // 设置点击背景进行关闭 Alert默认 NO , ActionSheet默认 YES
    .LeeCloseComplete(^{ 
    	// 关闭回调事件
    })
    .LeeShow();

关闭显示

    // 关闭指定标识的Alert或ActionSheet
    [LEEAlert closeWithIdentifier:@"xxxx" completionBlock:^{
        // 关闭完成
    }];

    // 关闭当前显示的Alert或ActionSheet
    [LEEAlert closeWithCompletionBlock:^{
    	
    	// 如果在关闭后需要做一些其他操作 建议在该Block中进行
    }];

注意事项

  • 在 AppDelegate 或 SceneDelegate 中设置主要Window: [LEEAlert configMainWindow:self.window];
  • 添加的功能项顺序会决定显示的排列顺序.
  • 当需要很复杂的样式时 如果默认提供的这些功能项无法满足, 建议将其封装成一个UIView对象 添加自定义视图来显示.
  • ActionSheet中 取消类型的Action 显示的位置与原生位置相同 处于底部独立的位置.
  • 设置最大宽度高度时如果使用CGRectGetWidth([[UIScreen mainScreen] bounds])这类方法 请考虑iOS8以后屏幕旋转 width和height会变化的特性.

其他问题

详情请查看Issues

安装

CocoaPods

  1. 将 cocoapods 更新至最新版本.
  2. 在 Podfile 中添加 pod 'LEEAlert'
  3. 执行 pod installpod update
  4. 导入 <LEEAlert/LEEAlert.h>

手动安装

  1. 下载 LEEAlert 文件夹内的所有内容。
  2. 将 LEEAlert 内的源文件添加(拖放)到你的工程。
  3. 导入 LEEAlert.h

系统要求

该库最低支持 iOS 8.0Xcode 11.0

版本更新

详情请查看更新日志

许可证

LEEAlert 使用 MIT 许可证,详情见 LICENSE 文件。

友情链接

高效的自动布局库 - SDAutoLayout

个人主页

我的简书

leealert's People

Contributors

kaelding avatar lixiang1994 avatar tory-xu avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

leealert's Issues

如何获取textField的内容

如何获取textField的内容,我再弹出框显示一个textField,想获取内容。比如弹出个输入密码,输入之后确定,想在确定的时候获取到内容

LEEAction 背后的白线如何隐藏

LEEAction背后有个白线 由于我设置LEEAction的背景为透明 所以上面出现了一条白线 由于这里无法上传图片 所以我没办法说明白 我看你写的Dome里面的显示一个新手红包的alert弹框里面的LEEAction背后也是有个白线 如果可以+我QQ 我发下分层的截图给你看 或者你看你的demo 我就想知道如何隐藏

好库

感谢作者的库 好用! 问题都是我自己没想周到

swift4 ios12 弹出失效

在swift4
ios12
xcode Version 10.0
的环境中, 代码执行无效(没有弹出框);

LEEAlert.alert().config.leeTitle("烯烃").leeContent("这是测试").leeShow;

关于LeeShow();之后textView失去响应者的问题。

页面中存在textView,在LEEAlert显示之后,textView会失去第一响应者,这个问题应该怎么解决,我在源码里面将LeeWindow的endEditing设置为NO也没解决这个问题。
第二,addContent中,为label设置富文本,结果富文本中的tapAction无法生效,估计也是这个第一响应者的原因,请大佬看到这条issuse尽快回复一下我,不胜感激。

不支持iPad

你好,我用了这个框架,但是没法适配ipad

可否实现二次封装

你好, 我觉得目前这种实现还算不上简单易用, 如果在一个页面上需要根据情况展示不同类型的alertview, 目前只能每个都重新实现一遍, 可否封装成那种可以动态添加item的实现呢?

关于自定义view,希望添加使用XIB 和 storyboard的demo。

目前项目中使用的customView是从XIB中或者storyboard中实例化出来的,但是frame总是不对,不知是不是我使用的方法不对,还是怎么的。如果可以的话希望增加一个demo,弹出一个XIB中的View,如果需要我也可以提供自己写的demo,供你修改。

循环引用

链式编程中的__weak 是不是没有必要?

先把基础的东西配置好,然后再配置一些动态的东西,最后再调用LeeShow,为啥不行呢?

怕描述的不是很清楚,直接贴代码出来吧。就是封装了sheet是一个数组的方法。

  • (void)HDShowActionSheet:(NSString *)title detail:(NSString *)detail sheets:(NSArray *)sheets result:(VoidBlock_int)result{

    LEEAlertConfigModel *alertConfigModel = [LEEAlert actionsheet].config
    .LeeAddTitle(^(UILabel *label) {

      label.text = title;
      
      label.textColor = [UIColor whiteColor];
    

    })
    .LeeAddContent(^(UILabel *label) {

      label.text = detail;
      
      label.textColor = [[UIColor whiteColor] colorWithAlphaComponent:0.75f];
    

    })
    .LeeAddAction(^(LEEAction *action) {

      action.type = LEEActionTypeCancel;
      
      action.title = @"取消";
      
      action.titleColor = HDColorTheme;;
      
      action.backgroundColor = [UIColor whiteColor];
      
      action.clickBlock = ^{
          
          // 取消点击事件Block
      };
    

    })
    .LeeHeaderColor(HDColorTheme);

    [sheets enumerateObjectsUsingBlock:^(NSString *obj, NSUInteger idx, BOOL * _Nonnull stop) {
    alertConfigModel
    .LeeAddAction(^(LEEAction *action) {

          action.type = LEEActionTypeDefault;
          
          action.title = obj;
          
          action.titleColor = HDColorTheme;
          
          action.backgroundColor = [UIColor whiteColor];
          
          action.clickBlock = ^{
              
              if (result) {
                  result(idx);
              }
              
          };
      });
    

    }];
    //
    alertConfigModel.LeeShow();

}

可否增加不允许 scrollView 不允许滚动的操作?

`[LEEAlert alert]
.config
.LeeItemInsets(UIEdgeInsetsMake(0, 0, 0, 0))
.LeeHeaderInsets(UIEdgeInsetsMake(0, 0, 0, 0))
.LeeMaxWidth(320)
.LeeMaxHeight(540)
.LeeAddCustomView(^(LEECustomView *custom) {
custom.view = view;
custom.positionType = LEECustomViewPositionTypeCenter;

                            })
                            .LeeClickBackgroundClose(YES)
                            .LeeShow();`

调整了各种布局 总是 会导致custom view 的高度会加上 LEEAlert的scrollview高度 导致滚动空白效果

新需求

darling,这个加个多个视图同时弹出吗? 不加队列里 一个一个显示 一次显示多个那种 多谢多谢 我太翔了,代码我自己改不动。

actionsheet 整体下移

请问如何实现整体向下移动offset y呢?

希望可以整体往下移动

具体请看看图片~
2019-02-22 9 47 50

关于代码

不知道作者为什么把封装都写在一个文件,我全部看了一遍代码,封装的到位,就是因为都在一个文件 阅读起来非常不方便,应该用的是构建者模式设计的,不知道作者ios写多少年了

一个issues & 一个建议

issues是。。。在 LeeAddTextField 的block回调内 如果加上 [tf becomeFirstResponder] 那么在肾5s上 键盘会把 action框的按钮遮挡住且无法取消到收键盘!

建议是。。。 如果手动点TextField 键盘起来 然后 alert的位置会自动往上移 避免被遮挡,但是感觉速度有点慢 建议能不能不要键盘完全出现后再 往上移,而是键盘willshow 通知的 的时候 就开始往上同步移动alert框?或者提供接口让开发者自己设置 往上移动的时机? 望作者大大采纳。谢谢

Swift

swift版的啥时候出来

sheet

怎么动态的控制sheet的个数呢?

8.0+的系统会崩溃

bugly抓的信息是
SEGV_ACCERR
-[UIView(LEEShadowViewHandle) lee_alert_dealloc],我是手动集成的,在10.0+的系统不会崩溃,9.0+没试过,当push到一个控制器再从那个控制器返回就崩溃了

allShareView里面报了很多错误

  • (void)safeAreaInsetsDidChange{

    [super safeAreaInsetsDidChange];

    self.shareScrollView.sd_layout
    .topSpaceToView(self.backGroundView , 20)
    .leftSpaceToView(self.backGroundView , VIEWSAFEAREAINSETS(self).left)
    .rightSpaceToView(self.backGroundView , VIEWSAFEAREAINSETS(self).left)
    .heightIs(100);

    if (isShowMore) {

      self.moreScrollView.sd_layout
      .topSpaceToView(self.lineView , 10)
      .leftSpaceToView(self.backGroundView , VIEWSAFEAREAINSETS(self).left)
      .rightSpaceToView(self.backGroundView , VIEWSAFEAREAINSETS(self).left)
      .heightIs(100);
    

    }
    }
    这个方法是哪里来的,怎么有super?这个view是继承自UIView

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.