1.
[[UIColor redColor] setStroke]; //描边
2.
[[UIColor yellowColor]setFill]; //填充
3.
[[UIColor greenColor]set] //描边填充通用
4.GRB 0-255
OC 中 0~1
-(void)drawRect:(CGRect)rect{
NSArray*array=@[@25,@25,@50];
CGFloat startP=0;
CGFloat angle = 0.0;
CGFloat endP = 0.0;
// NSInteger index=0;
CGPoint center=CGPointMake(self.bounds.size.width/2, self.bounds.size.height/2);
for (NSNumber*number in array) {
startP=endP;
angle=[number doubleValue]/100*M_PI*2;
endP=startP+angle;
UIBezierPath*path=[UIBezierPath bezierPathWithArcCenter:center radius:self.bounds.size.width/2 startAngle:startP endAngle:endP clockwise:YES];
[path addLineToPoint:center];
[[self randomColor]setFill];
[path fill];
}
}
-(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
[self setNeedsDisplay];
}
-(UIColor*)randomColor{
CGFloat r=arc4random_uniform(256)/255.0;
CGFloat g=arc4random_uniform(256)/255.0;
CGFloat b=arc4random_uniform(256)/255.0;
return [UIColor colorWithRed:r green:g blue:b alpha:1];
}