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. 网易云首席安全架构师谈安全新形势:DDOS两三天,游戏玩家数从几万降到几百

    本文由  网易云发布. 安全是一个永恒的话题,在业务不断云化.攻击越来越复杂的当下,互联网安全呈现了出什么样的严峻形势?对这些形势,网易云又是如何应对的? 网易云首席安全架构师沈明星 4月13日,网易 ...

  2. day 104 luffy项目第二天

    一.前端配置 二.后端配置 一.前端配置 app.vue 二 . 后端配置 model模型配置 迁移数据 序列化 views.py文件配置 url路由 配置中间件解决跨域问题 重新设计下 model模 ...

  3. 文件操作(FILE)与常用文件操作函数

    文件 1.文件基本概念 C程序把文件分为ASCII文件和二进制文件,ASCII文件又称文本文件,二进制文件和文本文件(也称ASCII码文件)二进制文件中,数值型数据是以二进制形式存储的, 而在文本文件 ...

  4. 用0x077CB531计算末尾0的个数

    http://www.matrix67.com/blog/archives/3985 unsigned int v;  // find the number of trailing zeros in ...

  5. Python爬虫之Cookie和Session

    关于cookie和session估计很多程序员面试的时候都会被问到,这两个概念在写web以及爬虫中都会涉及,并且两者可能很多人直接回答也不好说的特别清楚,所以整理这样一篇文章,也帮助自己加深理解 什么 ...

  6. POJ 1118

    #include<iostream> #include<set> #include<stdio.h> #include<math.h> #include ...

  7. WinForm—控制文本框只能输入整数(包括小数)

    //控制控件输入的是正数(包括小数) private void txt_Weight_KeyPress(object sender, KeyPressEventArgs e) { //第一步:判断输入 ...

  8. 批量导入数据到HBase

    hbase一般用于大数据的批量分析,所以在很多情况下需要将大量数据从外部导入到hbase中,hbase提供了一种导入数据的方式,主要用于批量导入大量数据,即importtsv工具,用法如下:   Us ...

  9. windows 安装openssl

    参考文章:http://www.cnblogs.com/tangxin-blog/p/5724071.html 准备条件: 1.VS2012 (携带c++) 2.下载openssl 源码 3.安装Pe ...

  10. Linux驱动:SPI驱动编写要点

    题外话:面对成功和失败,一个人有没有“冠军之心”,直接影响他的表现. 几周前剖析了Linux SPI 驱动框架,算是明白个所以然,对于这么一个庞大的框架,并不是每一行代码都要自己去敲,因为前人已经把这 ...