您的位置:首页 > 其它

Quartz2D - 画柱状图

2016-03-06 19:02 309 查看


//
//  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
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: