1.

.h文件

#import <UIKit/UIKit.h>

#define Wi [[UIScreen mainScreen]bounds].size.width

#define He [[UIScreen mainScreen]bounds].size.height

@interface Alert : UIView

typedef enum{
    AlertStyleYes=0,
    AlertStyleNo,
    AlertStyleWarning,
}AlertStyle;

@property(nonatomic,strong) UIView *alertView;

@property(nonatomic,strong) UIView *drawView;

@property(nonatomic) AlertStyle alertStyle;

@property(nonatomic,strong) UILabel *alertLabel;

@property(nonatomic,strong) UILabel *messageLabel;

@property(nonatomic,strong) UIButton *cancelButton;

@property(nonatomic,strong) UIButton *confirmButton;

-(instancetype)initAlertWithStyle:(AlertStyle)alertStyle;

@end

.m文件

#import "Alert.h"

@implementation Alert

-(instancetype)initAlertWithStyle:(AlertStyle)alertStyle{
    CGRect frame=  CGRectMake(0, 0, Wi, He);
    self=[super initWithFrame:frame];
    if (self) {
        
        self.backgroundColor=[UIColor colorWithRed:0.1 green:0.2 blue:0.3 alpha:0.3];
        //
       // self.center=CGPointMake(Wi/2, He/2);
        //
        [self initViews];
        
        //
        if (alertStyle==AlertStyleNo) {
            [self drawNo];
        }
        if (alertStyle==AlertStyleYes) {
            [self drawYes];

}
        if (alertStyle==AlertStyleWarning) {
            [self drawWarning];

}
     
        
    }
    return self;
}

/*
 初始化视图
*/
-(void)initViews{
    //
    self.alertView=[[UIView alloc]initWithFrame:CGRectMake(0, 0, 160, 190)];
    self.alertView.backgroundColor=[UIColor colorWithRed:0.8 green:0.8 blue:1.5 alpha:0.9];
    self.alertView.layer.masksToBounds=YES;
    self.alertView.layer.cornerRadius=5;
    self.alertView.center=self.center;
    [self addSubview:self.alertView];
    //
    self.drawView=[[UIView alloc]initWithFrame:CGRectMake(0, 0, 160, 110)];
  //  self.drawView.backgroundColor=[UIColor blackColor];
    [self.alertView addSubview:self.drawView];
    //
    self.alertLabel=[[UILabel alloc]initWithFrame:CGRectMake(0, 95, self.drawView.frame.size.width, 30)];
    self.alertLabel.textAlignment=1;
    _alertLabel.text=@"alertLabel";
    [self.alertView bringSubviewToFront:_alertLabel];
    [self.alertView addSubview:_alertLabel];
    //
    self.messageLabel=[[UILabel alloc]initWithFrame:CGRectMake(0, 120, self.drawView.frame.size.width, 30)];
    self.messageLabel.textAlignment=1;
    _messageLabel.text=@"messageLabel";
    [self.alertView bringSubviewToFront:_messageLabel];
    [self.alertView addSubview:_messageLabel];
    //
    _cancelButton=[UIButton buttonWithType:UIButtonTypeCustom];
    [_cancelButton setFrame:CGRectMake(10, 150, 60, 30)];
    [_cancelButton setTitle:@"取消" forState:UIControlStateNormal];
    [_cancelButton addTarget:self action:@selector(back) forControlEvents:UIControlEventTouchUpInside];
    [_cancelButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    _cancelButton.backgroundColor=[UIColor colorWithRed:0.1 green:0.2 blue:0.5 alpha:0.8];
    _cancelButton.layer.masksToBounds=YES;
    _cancelButton.layer.cornerRadius=5;
    [self.alertView addSubview:_cancelButton];
    //
    _confirmButton=[UIButton buttonWithType:UIButtonTypeCustom];
    [_confirmButton setFrame:CGRectMake(90, 150, 60, 30)];
    [_confirmButton setTitle:@"确定" forState:UIControlStateNormal];
    [_confirmButton addTarget:self action:@selector(back) forControlEvents:UIControlEventTouchUpInside];
    [_confirmButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    _confirmButton.backgroundColor=[UIColor colorWithRed:0.6 green:0.3 blue:0.2 alpha:0.8];
    _confirmButton.layer.masksToBounds=YES;
    _confirmButton.layer.cornerRadius=5;
    [self.alertView addSubview:_confirmButton];
    
}
-(void)back{
    [self removeFromSuperview];
}
/*
 设置alertStyle
*/
-(void)setAlertStyle:(AlertStyle)alertStyle{

_alertStyle=alertStyle ;
    [self addSubview:self.alertView];
    if (alertStyle==AlertStyleNo) {
        [self drawNo];
    }
    if (alertStyle==AlertStyleYes) {
        [self drawYes];
        
    }
    if (alertStyle==AlertStyleWarning) {
        [self drawWarning];
        
    }

}
/**************************三个绘制*****************************/

/*
 绘制yes
*/
-(void)drawYes{
    //先移除再绘制
    [self.drawView.layer.sublayers makeObjectsPerformSelector:@selector(removeFromSuperlayer) ];
    _alertLabel.text=@"Yes";
    _alertLabel.textColor=[UIColor blueColor];
    //
    _messageLabel.text=@"登陆成功";
    _messageLabel.textColor=[UIColor grayColor];
    //
    UIBezierPath *path = [UIBezierPath bezierPath];
    [path moveToPoint:CGPointMake(120, 50)];
    [path addArcWithCenter:CGPointMake(80, 50) radius:40 startAngle:2*M_PI endAngle: 0 clockwise:0];
    [path moveToPoint:CGPointMake(60,50)];
    [path addLineToPoint:CGPointMake(80, 70)];
    [path addLineToPoint:CGPointMake(110, 30)];
    
    // NSLog(@"%f",M_PI);
    //
    CAShapeLayer *pathLayer = [CAShapeLayer layer];
    pathLayer.frame = self.bounds;
    pathLayer.path = path.CGPath;
    pathLayer.strokeColor = [[UIColor blueColor] CGColor];
    pathLayer.fillColor = nil;
    pathLayer.lineWidth = 4.0f;
    pathLayer.lineJoin = kCALineJoinBevel;
    
    
    [self.drawView.layer addSublayer:pathLayer];
    //
    CABasicAnimation *pathAnimation = [CABasicAnimation animationWithKeyPath:@"strokeEnd"];
    //pathAnimation = [CABasicAnimation animationWithKeyPath:@"strokeEnd"];
    pathAnimation.duration =0.5;
    pathAnimation.fromValue = [NSNumber numberWithFloat:0.0f];
    pathAnimation.toValue = [NSNumber numberWithFloat:1.0f];
    [pathLayer addAnimation:pathAnimation forKey:@"strokeEnd"];

}
/*
 绘制No
*/
-(void)drawNo{
    //先移除再绘制
    [self.drawView.layer.sublayers makeObjectsPerformSelector:@selector(removeFromSuperlayer) ];
    //
    _alertLabel.text=@"登陆失败";
    _alertLabel.textColor=[UIColor redColor];
    //
    _messageLabel.text=@"密码输入错误";
    _messageLabel.textColor=[UIColor grayColor];
    //
    UIBezierPath *path=[UIBezierPath bezierPath];
    [path moveToPoint:CGPointMake(40, 10)];
    [path addLineToPoint:CGPointMake(40, 90)];
    [path addLineToPoint:CGPointMake(120, 90)];
    [path addLineToPoint:CGPointMake(120, 10)];
    [path addLineToPoint:CGPointMake(40, 10)];
    
    [path moveToPoint:CGPointMake(60, 30)];
    [path addLineToPoint:CGPointMake(100, 70)];
    
    [path moveToPoint:CGPointMake(100, 30)];
    [path addLineToPoint:CGPointMake(60, 70)];
    //
    CAShapeLayer *pathLayer = [CAShapeLayer layer];
    pathLayer.frame = self.bounds;
    pathLayer.path = path.CGPath;
    pathLayer.strokeColor = [[UIColor redColor] CGColor];
    pathLayer.fillColor = nil;
    pathLayer.lineWidth = 4.0f;
    pathLayer.lineJoin = kCALineJoinBevel;
    [self.drawView.layer addSublayer:pathLayer];

//
    CABasicAnimation *pathAnimation = [CABasicAnimation animationWithKeyPath:@"strokeEnd"];
    pathAnimation = [CABasicAnimation animationWithKeyPath:@"strokeEnd"];
    pathAnimation.duration = 0.5;
    pathAnimation.fromValue = [NSNumber numberWithFloat:0.0f];
    pathAnimation.toValue = [NSNumber numberWithFloat:1.0f];
    [pathLayer addAnimation:pathAnimation forKey:@"strokeEnd"];

}
/*
 绘制Warning
 */
-(void)drawWarning{
    //先移除再绘制
    [self.drawView.layer.sublayers makeObjectsPerformSelector:@selector(removeFromSuperlayer) ];
    //
    _alertLabel.text=@"警告";
    _alertLabel.textColor=[UIColor colorWithRed:1.4 green:1.0 blue:0 alpha:1.0];
    //
    _messageLabel.text=@"内存不足";
    _messageLabel.textColor=[UIColor grayColor];
    //
    UIBezierPath *path=[UIBezierPath bezierPath];
    [path moveToPoint:CGPointMake(80, 10)];
    [path addLineToPoint:CGPointMake(30, 95)];
    [path addLineToPoint:CGPointMake(130, 95)];
    [path addLineToPoint:CGPointMake(80, 10)];
    
    [path moveToPoint:CGPointMake(80, 30)];
    [path addLineToPoint:CGPointMake(80, 75)];
    
    [path moveToPoint:CGPointMake(80, 80)];
    [path addLineToPoint:CGPointMake(80, 85)];
    //
    CAShapeLayer *pathLayer = [CAShapeLayer layer];
    pathLayer.frame = self.bounds;
    pathLayer.path = path.CGPath;
    pathLayer.strokeColor = [[UIColor yellowColor] CGColor];
    pathLayer.fillColor = nil;
    pathLayer.lineWidth = 4.0f;
    pathLayer.lineJoin = kCALineJoinBevel;
    
    [self.drawView.layer addSublayer:pathLayer];
    
    //
    CABasicAnimation *pathAnimation = [CABasicAnimation animationWithKeyPath:@"strokeEnd"];
    pathAnimation = [CABasicAnimation animationWithKeyPath:@"strokeEnd"];
    pathAnimation.duration = 0.5;
    pathAnimation.fromValue = [NSNumber numberWithFloat:0.0f];
    pathAnimation.toValue = [NSNumber numberWithFloat:1.0f];
    [pathLayer addAnimation:pathAnimation forKey:@"strokeEnd"];
    
}

/*
//
 UIBezierPath *path = [UIBezierPath bezierPath];
 [path moveToPoint:CGPointMake(0.0,20.0)];
 [path addLineToPoint:CGPointMake(120.0, 500.0)];
 [path addLineToPoint:CGPointMake(220, 0)];
 [path addLineToPoint:CGPointMake(310, 40)];
 [path addLineToPoint:CGPointMake(SCREEN_WIDTH, 110)];
 //
 CAShapeLayer *pathLayer = [CAShapeLayer layer];
 pathLayer.frame = self.view.bounds;
 pathLayer.path = path.CGPath;
 pathLayer.strokeColor = [[UIColor redColor] CGColor];
 pathLayer.fillColor = nil;
 pathLayer.lineWidth = 2.0f;
 pathLayer.lineJoin = kCALineJoinBevel;
 [self.view.layer addSublayer:pathLayer];
 //
 CABasicAnimation *pathAnimation = [CABasicAnimation animationWithKeyPath:@"strokeEnd"];
 pathAnimation = [CABasicAnimation animationWithKeyPath:@"strokeEnd"];
 pathAnimation.duration = 2.0;
 pathAnimation.fromValue = [NSNumber numberWithFloat:0.0f];
 pathAnimation.toValue = [NSNumber numberWithFloat:1.0f];
 [pathLayer addAnimation:pathAnimation forKey:@"strokeEnd"];
*/

@end

2.效果:

自定义提醒视图Alert-动态绘制的更多相关文章

  1. iOS可视化动态绘制连通图

    上篇博客<iOS可视化动态绘制八种排序过程>可视化了一下一些排序的过程,本篇博客就来聊聊图的东西.在之前的博客中详细的讲过图的相关内容,比如<图的物理存储结构与深搜.广搜>.当 ...

  2. C# 动态绘制任务栏图标的实现

    通常我们在做一个应用时会遇到这样的需求:将收到的消息条数显示到任务栏,比如如下的效果 怎么实现呢? 答案是采用WindowsAPICodePack实现,具体参见:Windows 7 任务栏开发 之 覆 ...

  3. 自定义View视图

    自定义View视图文件查找逻辑 之前MVC5和之前的版本中,我们要想对View文件的路径进行控制的话,则必须要对IViewEngine接口的FindPartialView或FindView方法进行重写 ...

  4. iOS可视化动态绘制连通图(Swift版)

    上篇博客<iOS可视化动态绘制八种排序过程>可视化了一下一些排序的过程,本篇博客就来聊聊图的东西.在之前的博客中详细的讲过图的相关内容,比如<图的物理存储结构与深搜.广搜>.当 ...

  5. 自定义view:view的绘制流程

    1.view的绘制流程 当 Activity 接收到焦点的时候,它会被请求绘制布局,该请求由 Android framework 处理.绘制是从根节点开始,对布局树进行 measure 和 draw. ...

  6. (排班表二)后台动态绘制Grid表格

    后台动态绘制值班表(Grid表格 列名不固定) 要求:表头除了值班人姓名,还要显示日期,及每天的星期值,用斜杠‘/’分隔.即:几号/星期几 最终实现的效果:根据查询的年月显示每个值班人查询月份每天的值 ...

  7. 1.Android 视图及View绘制分析笔记之setContentView

    自从1983年第一台图形用户界面的个人电脑问世以来,几乎所有的PC操作系统都支持可视化操作,Android也不例外.对于所有Android Developer来说,我们接触最多的控件就是View.通常 ...

  8. UICollectionView(集合视图)以及自定义集合视图

    一.UICollectionView集合视图           其继承自UIScrollView.         UICollectionView类是iOS6新引进的API,用于展示集合视图,布局 ...

  9. Android 自定义View修炼-自定义HorizontalScrollView视图实现仿ViewPager效果

    开发过程中,需要达到 HorizontalScrollView和ViewPager的效果,于是直接重写了HorizontalScrollView来达到实现ViewPager的效果. 实际效果图如下: ...

随机推荐

  1. requirejs的插件介绍与制作

    本文由作者郑海波授权网易云社区发布. 前言 我这里就不介绍requirejs了, 简而言之: requirejs是支持AMD规范的模块加载器, 事实上它也是AMD的最直接推动者. 现在可供挑选的开源模 ...

  2. jzoj5888

    tj:暴力連邊會tle 我們發現所有邊的邊權最大值不超過100000,這意味著可以設計和邊權有關的算法,假設現在邊權不相同 枚舉一個現在的邊權i,代表gcd為i,設連的2個點權值為a1∗ia1*ia1 ...

  3. spring-security(2)

    记录一下spring security的配置 配置详解 <?xml version="1.0" encoding="UTF-8"?> <bea ...

  4. myeclipse注册码生成

    import java.io.*; /** * <一句话功能简述> * <功能详细描述> * * @author 程松 * @date 2013-11-8上午8:50:34 * ...

  5. [Other] 应用下载网站的APK/IPA等常见MIME设置

    类型 扩展名 mime 错误做法 安卓安装包 .apk application/vnd.android.package-archive application/vnd.android 苹果安装包 .i ...

  6. sublime text 内调试Javascript代码

    转自:sublime内调试Javascript代码 之前用webstorm, 可以直接调试js, 在浏览器中也可以调试js,最近换了sublime text, 在想它是否支持调试js代码,于是找到了这 ...

  7. Jmeter修改自身启动IP

    先说一下问题,控制机访问压力机都是可以的,但是压力机访问控制机就不行了报:2019/04/13 16:05:49 ERROR - jmeter.samplers.RemoteTestListenerW ...

  8. NSCache 的好处

    相较于 NSDictionary 线程安全 系统资源将要耗尽时,自动删减缓存 自动删减"最久未使用的"对象 不会自动拷贝键.因为有些键不支持拷贝操作 可以和 NSPurgeable ...

  9. cobbler 自定义安装系统

    1.自定义安装系统(根据mac地址)--name=定义名称--mac=客户端的mac地址--ip-address=需求的ip--subnet=掩码 --gateway=网关--interface=网口 ...

  10. Linux Cluster环境下批量分发执行补丁

    转自:http://blog.csdn.net/napolunyishi/article/details/18219867 这两天做了一个需求,因为上一个版本的/tmp空间默认只分配了5G,而升级程序 ...