//
// BarView.m
#import "BarView.h"
@implementation BarView
- (void)drawRect:(CGRect)rect
{
// 数据
NSArray *arr = @[@25,@25,@50];
//属性值
CGFloat x = 0;
CGFloat y = 0;
CGFloat w = 0;
CGFloat h = 0;
for (int i=0; i<arr.count; i++) {
w = rect.size.width / (arr.count * 2 - 1);
x = 2 * w * i;
h = [arr[i] floatValue] / 100.0 * rect.size.height;
y = rect.size.height - h;
UIBezierPath *path = [UIBezierPath bezierPathWithRect:CGRectMake(x, y, w, h)];
[[self colorRandom] set];
[path fill];
}
}
/**
* 随机一个颜色
*/
- (UIColor *)colorRandom
{
CGFloat red = arc4random_uniform(256) / 255.0;
CGFloat green = arc4random_uniform(256) / 255.0;
CGFloat blue = arc4random_uniform(256) / 255.0;
return [UIColor colorWithRed:red green:green blue:blue alpha:1.0];
}
@end
Quartz2D - 画柱状图
最新推荐文章于 2020-10-14 20:04:54 发布