#import "DrawView.h"
@implementation DrawView
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
// Drawing code
UIBezierPath *path = [UIBezierPath bezierPath];
[path moveToPoint:CGPointMake(0, 300)];
[path addLineToPoint:CGPointMake(300, 300)];
[path moveToPoint:CGPointMake(0, 300)];
[path addLineToPoint:CGPointMake(0, 0)];
path.lineWidth = 5;
[path stroke];
int line = 0;
NSArray *dataArr = @[@100,@200,@200,@250,@10,@20];
for (NSNumber *num in dataArr) {
CGPoint startPoint = CGPointMake(30 + line * 300/dataArr.count, 300);
CGPoint endPoint = CGPointMake(30 + line * 300/dataArr.count, 300 - 300 * (num.intValue / 300.0));
UIBezierPath *path = [UIBezierPath bezierPath];
[path moveToPoint:startPoint];
[path addLineToPoint:endPoint];
path.lineWidth = 20;
[path stroke];
line ++;
}
}
-(void)shape1{
//方形
// UIBezierPath *path = [UIBezierPath bezierPathWithRect:CGRectMake(50, 50, 200, 200)];
// //填充
// [path fill];
//橢圓
// UIBezierPath *path = [UIBezierPath bezierPathWithOvalInRect:CGRectMake(50, 50, 200, 200)];
// [path stroke];
//圓角
// UIBezierPath *path = [UIBezierPath bezierPathWithRoundedRect:self.bounds cornerRadius:150];
// [path stroke];
//圓(扇形) startAngle是從三點方向開始畫 clockwise是順時針
UIBezierPath *path = [UIBezierPath bezierPathWithArcCenter:CGPointMake(150, 150) radius:100 startAngle:0 endAngle:M_PI_2 clockwise:YES];
[path addLineToPoint:CGPointMake(150, 150)];
[path closePath];
[path stroke];
UIBezierPath *path2 = [UIBezierPath bezierPathWithArcCenter:CGPointMake(150, 150) radius:100 startAngle:M_PI_2 endAngle:M_PI_2 + M_PI_2 clockwise:YES];
[[UIColor redColor] set];
[path2 addLineToPoint:CGPointMake(150, 150)];
[path2 closePath];
[path2 stroke];
UIBezierPath *path3 = [UIBezierPath bezierPathWithArcCenter:CGPointMake(150, 150) radius:100 startAngle:M_PI_2 *2 endAngle:M_PI_2 * 3 clockwise:YES];
[[UIColor yellowColor] set];
[path3 addLineToPoint:CGPointMake(150, 150)];
[path3 closePath];
[path3 stroke];
UIBezierPath *path4 = [UIBezierPath bezierPathWithArcCenter:CGPointMake(150, 150) radius:100 startAngle:M_PI_2 *3 endAngle:M_PI_2 * 4 clockwise:YES];
[[UIColor orangeColor] set];
[path4 addLineToPoint:CGPointMake(150, 150)];
[path4 closePath];
[path4 stroke];
}
- (void)shape2{
NSArray *dataArray = @[@20,@10,@10,@10,@10,@20,@20];
//記錄起點和終點
CGFloat start = 0;
CGFloat end = 0;
// 遍歷數(shù)據(jù)
for (NSNumber *num in dataArray) {
end = num.floatValue / 100 *M_PI *2;
UIBezierPath *path = [UIBezierPath bezierPathWithArcCenter:CGPointMake(150, 150) radius:100 startAngle:start endAngle:start + end clockwise:YES];
//關(guān)閉路徑
[path addLineToPoint:CGPointMake(150, 150)];
[path closePath];
[[UIColor colorWithRed:arc4random()%256 / 255.0 green:arc4random()%256 / 255.0 blue:arc4random()%256 / 255.0 alpha:1] set];
[path fill];
start += end;
}
}
@end
QuartZ2D_02
最后編輯于 :
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。
相關(guān)閱讀更多精彩內(nèi)容
- 做正確的事遠比把事情做對重要的多。笑來老師今天的概念讓我發(fā)現(xiàn)自己身上的一個問題!從訂閱笑來老師的專欄后也關(guān)注了好多...