在家閑來無事,于是就看起來ios繪圖的那塊,寫點什么好呢?
鼓搗了一會,總算寫出了一個小東西
這個是寫完以后的效果
這里我實現了三種款式的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];
這個代碼段是用來繪制一個嘆號
新聞熱點
疑難解答