#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;
// 遍历数据
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];
//关闭路径
[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
最后编辑于 :
©著作权归作者所有,转载或内容合作请联系作者
- 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
- 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
- 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...