在家閑來無事缤谎,于是就看起來ios繪圖的那塊渗鬼,寫點什么好呢刹衫?
鼓搗了一會,總算寫出了一個小東西
這個是寫完以后的效果
這里我實現(xiàn)了三種款式的alertview
分別是成功口糕,錯誤和警告缅阳,剩下的呢有空繼續(xù)添加吧。
廢話不說了景描,講一下代碼的思路
我用的是UIBezierPath進行繪圖
ios有很多種繪圖的方式十办,要講的話在寫幾篇都寫不完,這里就不詳細(xì)介紹了超棺。
UIBezierPath繪圖分三個步驟
1.創(chuàng)建UIBezierPath路徑
2.創(chuàng)建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];
這個代碼段是用來繪制一個嘆號