iOS自定义alertview

作者: HarriesChen | 来源:发表于2015-02-12 23:15 被阅读2473次

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

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

这个是写完以后的效果

imageimage imageimage imageimage

这里我实现了三种款式的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代码在这

相关文章

  • 自定义AlertView

    自定义AlertView 之囧事 昨天被 AlertView、AlertController虐了 ...然鹅发现...

  • ios自定义AlertView

    先上图,弹框的背景色,按钮背景色,提示的消息的字体颜色都可以改变 利用单例实现丰富的自定义接口 .m文件中初始化控...

  • iOS自定义alertview

    在家闲来无事,于是就看起来ios绘图的那块,写点什么好呢? 鼓捣了一会,总算写出了一个小东西 这个是写完以后的效果...

  • iOS 自定义AlertView

    iOS 自带的UIAlertView 与UIAlertController功能非常局限,有时候需要我们自定义Ale...

  • iOS自定义AlertView

    ELAlertView ELAlertView 可以定制化弹框的外形和其内容,最关键的是可以放置图片. 你可以使...

  • iOS自定义AlertView

    在iOS开发中,我们经常会用到一些提示框或者一些弹出菜单,但是这些视图系统自带的视图是满足不了的,比如这种:Wec...

  • IOS 提示框UIAlertView,UIActionSheet

    一:UIAlertView警告框 IOS 2 - IOS 9 UIAlertView*AlertView=[[UI...

  • ios AlertView 自定义弹窗

    自定义弹窗,虽然同样的Dome很多,但我还是厚颜无耻的再共享一个自己写的吧!这个弹窗我定义了两种实现模式,一种是 ...

  • iOS 自定义AlertView(OC)

    最近项目中,要使用AlertView提示框,其实和UIAlertView类似的方式,只是按钮颜色发生修改。Aler...

  • iOS自定义控件-AlertView

    本控件项目地址,希望能给个start,欢迎大家交流指正。 简单说明 有简单动画效果,高度可根据内容自适应,点击事件...

网友评论

本文标题:iOS自定义alertview

本文链接:https://www.haomeiwen.com/subject/urusxttx.html