在家閑來無事,于是就看起來ios繪圖的那塊,寫點(diǎn)什么好呢?
鼓搗了一會(huì),總算寫出了一個(gè)小東西
這個(gè)是寫完以后的效果

image

image

image
這里我實(shí)現(xiàn)了三種款式的alertview
分別是成功,錯(cuò)誤和警告,剩下的呢有空繼續(xù)添加吧。
廢話不說了,講一下代碼的思路
我用的是UIBezierPath進(jìn)行繪圖
ios有很多種繪圖的方式,要講的話在寫幾篇都寫不完,這里就不詳細(xì)介紹了。
UIBezierPath繪圖分三個(gè)步驟
1.創(chuàng)建UIBezierPath路徑
2.創(chuàng)建CAShapeLayer
3.將layer附加到圖層
2和3之間還可以添加動(dòng)畫
[_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];
這個(gè)代碼段是用來繪制一個(gè)嘆號(hào)