• Stars
    star
    1,297
  • Rank 36,000 (Top 0.8 %)
  • Language
    Objective-C
  • License
    MIT License
  • Created over 8 years ago
  • Updated 5 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

优雅的可自定义 Alert ActionSheet

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

个人主页

我的简书

More Repositories

1

AttributedString

基于Swift插值方式优雅的构建富文本, 支持点击长按事件, 支持不同类型过滤, 支持自定义视图等.
Swift
835
star
2

LEETheme

优雅的主题管理库- 一行代码完成多样式切换
Objective-C
816
star
3

AutoInch

优雅的iPhone全尺寸/等比例精准适配工具
Swift
463
star
4

NewsDetailsDemo

资讯详情文章页面Demo 内容部分为HTML数据格式 基于WKWebView加载 原生图片加载方式 (支持GIF图片) 支持持久化缓存等
Objective-C
87
star
5

LEECoolButton

一个炫酷的按钮(适用于喜欢 , 点赞 , 收藏等)
Objective-C
74
star
6

VideoTransitionDemo

视频过渡效果演示
Swift
71
star
7

LEEStarRating

星星评分视图控件 支持整颗 , 半颗 , 无限制评分 可自定义分数范围和星星个数等
Objective-C
60
star
8

UIAdapter

An elegant solution to the iOS screen adaptation problem
Swift
53
star
9

PermissionKit

An elegant permission manager written in swift
Swift
36
star
10

ViewControllerDemo

Swift 泛型 UIViewController的View分离演示
Swift
21
star
11

Router

基于URLNavigator抽象的外部URL路由组件 支持任意类型配置 插件机制
Swift
20
star
12

Loading

An elegant loading view written in swift
Swift
20
star
13

SKUFilterDemo

SKUFilter 电商Stock Keeping Unit选择过滤器示例
Swift
20
star
14

Apis

基于URLNavigator抽象的URL路由组件 灵感来自Moya 配置化 插件化.
Swift
17
star
15

Guider

An elegant highlight focus guide written in swift
Swift
10
star
16

Spring

An elegant animation written in swift
Swift
10
star
17

VideoPlayer

Swift
9
star
18

GearAnimationDemo

齿轮动画Demo
Objective-C
8
star
19

AudioPlayer

Swift
7
star
20

SDKit

简洁、高效的iOS开发“一站式”工具库
Objective-C
6
star
21

Alienware-Aurora-R13-Water-Cooling

外置压缩机水冷改装分享
5
star
22

LEEBubble

一个有趣的小气泡
Objective-C
5
star
23

Scanner

二维码扫描Demo
Swift
4
star
24

AsyncLayer

iOS 异步渲染Layer
Swift
3
star
25

IMInterface

Swift
2
star
26

VideoClipDemo

视频剪切Demo
Swift
2
star
27

LinearView

Linear layout view based on UIStackView Use chain encapsulation to quickly build vertical or horizontal layout views.
Swift
2
star
28

Specs

CocoaPods PodSpecs
Ruby
2
star
29

Resources

1
star
30

LEEResume

简历
JavaScript
1
star
31

Delegates

An elegant multiple delegate written in swift
Swift
1
star
32

ghost-lee-theme

Ghost Blog Themes (LEE)
CSS
1
star
33

QQMusicPlayerDemo

音乐播放器示例Demo 参考QQ音乐
Objective-C
1
star