画饼图
2015-11-27 23:26
302 查看
#import "BinTu.h"
@implementation BinTu
- (void)drawRect:(CGRect)rect {
NSArray *array = @[@25,@25,@50];
for (NSNumber *num
in array) {
[self drawPicture:num.floatValue andColour:[self randomColour]];
}
}
// 根据开始和结束角度画饼图
static CGFloat endA =
0;
- (void)drawPicture:(CGFloat)value andColour:(UIColor *)colour
{
CGPoint center = CGPointMake(self.bounds.size.width *
0.5, self.bounds.size.height *
0.5);
CGFloat radius = self.bounds.size.width *
0.5 - 20;
CGFloat startA = endA;
CGFloat spaceA = value /100.0 * M_PI *
2;
endA = startA + spaceA;
UIBezierPath *path = [UIBezierPath bezierPathWithArcCenter:center radius:radius startAngle:startA endAngle:endA clockwise:YES];
[path addLineToPoint:center];
[colour set];
[path fill];
}
// 创建随机颜色
- (UIColor *)randomColour
{
int numR = arc4random_uniform(256);
int numG = arc4random_uniform(256);
int numB = arc4random_uniform(256);
return [UIColor colorWithRed:numR/255.0 green:numG/255.0 blue:numB/255.0 alpha:1];
}
@end
@implementation BinTu
- (void)drawRect:(CGRect)rect {
NSArray *array = @[@25,@25,@50];
for (NSNumber *num
in array) {
[self drawPicture:num.floatValue andColour:[self randomColour]];
}
}
// 根据开始和结束角度画饼图
static CGFloat endA =
0;
- (void)drawPicture:(CGFloat)value andColour:(UIColor *)colour
{
CGPoint center = CGPointMake(self.bounds.size.width *
0.5, self.bounds.size.height *
0.5);
CGFloat radius = self.bounds.size.width *
0.5 - 20;
CGFloat startA = endA;
CGFloat spaceA = value /100.0 * M_PI *
2;
endA = startA + spaceA;
UIBezierPath *path = [UIBezierPath bezierPathWithArcCenter:center radius:radius startAngle:startA endAngle:endA clockwise:YES];
[path addLineToPoint:center];
[colour set];
[path fill];
}
// 创建随机颜色
- (UIColor *)randomColour
{
int numR = arc4random_uniform(256);
int numG = arc4random_uniform(256);
int numB = arc4random_uniform(256);
return [UIColor colorWithRed:numR/255.0 green:numG/255.0 blue:numB/255.0 alpha:1];
}
@end
相关文章推荐
- TinyOS论文04:Demo: Towards Bug-free Implementation for Wireless Sensor Networks
- oracle 基础1
- 森林病虫防治系统 (七)
- 南大软院大神养成计划--js
- quzed2D进度条
- 多种方法实现Excel批量导入数据库
- 欢迎使用CSDN-markdown编辑器
- nyoj+区间dp括号匹配
- 温故知新—Java8复习之始
- UITabBarController使用详解
- sicily 1205. brainf*ck
- Swift语言计算属性简单理解
- 程序的环境
- pushd popd shift ATTRIB
- CALayer的使用
- new和malloc的区别
- 加油!
- UINavigationController使用详解
- Windows/DOS与Unix文件格式之间的相互转换(/r/n问题)
- Python 面相对象 —— 类的三大成员