zoukankan      html  css  js  c++  java
  • IOS自定义alertview

    在家闲来无事,于是就看起来ios绘图的那块,写点什么好呢?

    鼓捣了一会,总算写出了一个小东西

    这个是写完以后的效果

    image

    image

    image

    这里我实现了三种款式的alertview
    分别是成功,错误和警告,剩下的呢有空继续添加吧。

    废话不说了,讲一下代码的思路

    我用的是UIBezierPath进行绘图

    ios有很多种绘图的方式,要讲的话在写几篇都写不完,这里就不详细介绍了。

    UIBezierPath绘图分三个步骤

    1.创建UIBezierPath路径
    2.创建CAShapeLayer
    3.将layer附加到图层

    2和3之间还可以添加动画

    
    [_logoView removeFromSuperview];
        _logoView = [[UIView alloc] initWithFrame:CGRectMake(([self getSelfSize].width-Simble_SIZE)/2, Simble_TOP, Simble_SIZE, Simble_SIZE)];
        
        UIBezierPath *path = [UIBezierPath bezierPathWithArcCenter:CGPointMake(Simble_SIZE/2, Simble_SIZE/2) radius:Simble_SIZE/2 startAngle:0 endAngle:M_PI*2 clockwise:YES];
        path.lineCapStyle = kCGLineCapRound;
        path.lineJoinStyle = kCGLineCapRound;
        
        [path moveToPoint:CGPointMake(Simble_SIZE/2, Simble_SIZE/6)];
        CGPoint p1 = CGPointMake(Simble_SIZE/2, Simble_SIZE/6*3.8);
        [path addLineToPoint:p1];
        
        [path moveToPoint:CGPointMake(Simble_SIZE/2, Simble_SIZE/6*4.5)];
        [path addArcWithCenter:CGPointMake(Simble_SIZE/2, Simble_SIZE/6*4.5) radius:2 startAngle:0 endAngle:M_PI*2 clockwise:YES];
        
        
        CAShapeLayer *layer = [[CAShapeLayer alloc] init];
        layer.fillColor = [UIColor clearColor].CGColor;
        layer.strokeColor = [UIColor orangeColor].CGColor;
        layer.lineWidth = 5;
        layer.path = path.CGPath;
        
        CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:NSStringFromSelector(@selector(strokeEnd))];
        animation.fromValue = @0;
        animation.toValue = @1;
        animation.duration = 0.5;
        [layer addAnimation:animation forKey:NSStringFromSelector(@selector(strokeEnd))];
        
        [_logoView.layer addSublayer:layer];
        
        [self addSubview:_logoView];
    
    

    这个代码段是用来绘制一个叹号

    GitHub代码在这

  • 相关阅读:
    【MySQL】DBA必备的10款最佳MySQL GUI工具
    【MySQL】获取MySQL崩溃时的core file
    字符串经常用的
    centos 系统上如何把python升级为3
    centos6 升级安装openssh7
    多进程
    队列
    线程池,锁,事件
    thread
    进程、线程
  • 原文地址:https://www.cnblogs.com/mrchenhao/p/4289351.html
Copyright © 2011-2022 走看看