iOS可旋转的饼图
来源:互联网 发布:3d怎么优化模型减少面 编辑:程序博客网 时间:2024/04/29 18:27
效果图:
代码下载:http://pan.baidu.com/s/1o6BGz0m http://download.csdn.net/detail/qqmcy/7090865
饼图的第三方类在例子中是有的,使用起来也很简单,下面是使用的代码。
ViewController.h
#import <UIKit/UIKit.h>#import "PieChartView.h"@interface ViewController : UIViewController<PieChartDelegate>@property (nonatomic,strong) NSMutableArray *m_valueArray; //第一组数据的容器@property (nonatomic,strong) NSMutableArray *m_colorArray; //第一组颜色的容器@property (nonatomic,strong) NSMutableArray *m_valueArray2;//第二组数据的容器@property (nonatomic,strong) NSMutableArray *m_colorArray2;//第二组颜色的容器@property (nonatomic,strong) PieChartView *m_pieChartView; //饼图类@property (nonatomic,strong) UIView *m_pieContainer; //饼图的容器@property (nonatomic)BOOL inOut; //点击中心的控制开关@property (nonatomic,strong) UILabel *m_selLabel; //显示数据的标签@end
ViewController.m
//// ViewController.m// 可旋转的饼图//// Created by 杜甲 on 14-3-24.// Copyright (c) 2014年 杜甲. All rights reserved.//#import "ViewController.h"#define PIE_HEIGHT 280@interface ViewController ()@end@implementation ViewController- (void)viewDidLoad{ self.inOut = YES; [super viewDidLoad];// Do any additional setup after loading the view, typically from a nib. self.m_valueArray = [[NSMutableArray alloc] initWithObjects: [NSNumber numberWithInt:12], [NSNumber numberWithInt:3], [NSNumber numberWithInt:2], [NSNumber numberWithInt:3], [NSNumber numberWithInt:3], [NSNumber numberWithInt:4], nil]; self.m_valueArray2 = [[NSMutableArray alloc] initWithObjects: [NSNumber numberWithInt:3], [NSNumber numberWithInt:2], [NSNumber numberWithInt:2], nil]; self.m_colorArray = [NSMutableArray arrayWithObjects: [UIColor colorWithHue:((0/8)%20)/20.0+0.08 saturation:(0%8+3)/10.0 brightness:91/100.0 alpha:1], [UIColor colorWithHue:((1/8)%20)/20.0+0.03 saturation:(1%8+3)/10.0 brightness:91/100.0 alpha:1], [UIColor colorWithHue:((2/8)%20)/20.0+0.12 saturation:(2%8+3)/10.0 brightness:91/100.0 alpha:1], [UIColor colorWithHue:((3/8)%20)/20.0+0.32 saturation:(3%8+3)/10.0 brightness:91/100.0 alpha:1], [UIColor colorWithHue:((4/8)%20)/20.0+0.01 saturation:(4%8+3)/10.0 brightness:91/100.0 alpha:1], [UIColor colorWithHue:((5/8)%20)/20.0+0.05 saturation:(5%8+3)/10.0 brightness:91/100.0 alpha:1], nil]; self.m_colorArray2 = [[NSMutableArray alloc] initWithObjects: [UIColor purpleColor], [UIColor orangeColor], [UIColor magentaColor], nil]; //add shadow img CGRect pieFrame = CGRectMake((self.view.frame.size.width - PIE_HEIGHT) / 2, 0, PIE_HEIGHT, PIE_HEIGHT); UIImage *shadowImg = [UIImage imageNamed:@"shadow.png"]; UIImageView *shadowImgView = [[UIImageView alloc]initWithImage:shadowImg]; shadowImgView.frame = CGRectMake(0, pieFrame.origin.y + PIE_HEIGHT*0.92, shadowImg.size.width/2, shadowImg.size.height/2); [self.view addSubview:shadowImgView]; self.m_pieContainer = [[UIView alloc]initWithFrame:pieFrame]; self.m_pieChartView = [[PieChartView alloc]initWithFrame:self.m_pieContainer.bounds withValue:self.m_valueArray withColor:self.m_colorArray]; self.m_pieChartView.delegate = self; [self.m_pieContainer addSubview:self.m_pieChartView]; [self.m_pieChartView setAmountText:@"-2456.0"]; [self.view addSubview:self.m_pieContainer]; //add selected view UIImageView *selView = [[UIImageView alloc]init]; selView.image = [UIImage imageNamed:@"select.png"]; selView.frame = CGRectMake((self.view.frame.size.width - selView.image.size.width/2)/2, self.m_pieContainer.frame.origin.y + self.m_pieContainer.frame.size.height, selView.image.size.width/2, selView.image.size.height/2); [self.view addSubview:selView]; self.m_selLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, 24, selView.image.size.width/2, 21)]; self.m_selLabel.backgroundColor = [UIColor clearColor]; self.m_selLabel.textAlignment = NSTextAlignmentCenter; self.m_selLabel.font = [UIFont systemFontOfSize:17]; self.m_selLabel.textColor = [UIColor whiteColor]; [selView addSubview:self.m_selLabel]; [self.m_pieChartView setTitleText:@"支出总计"]; self.title = @"对账单"; }- (void)selectedFinish:(PieChartView *)pieChartView index:(NSInteger)index percent:(float)per{ self.m_selLabel.text = [NSString stringWithFormat:@"%2.2f%@",per*100,@"%"];}- (void)onCenterClick:(PieChartView *)pieChartView{ self.inOut = !self.inOut; self.m_pieChartView.delegate = nil; [self.m_pieChartView removeFromSuperview]; self.m_pieChartView = [[PieChartView alloc]initWithFrame:self.m_pieContainer.bounds withValue:self.inOut?self.m_valueArray:self.m_valueArray2 withColor:self.inOut?self.m_colorArray:self.m_colorArray2]; self.m_pieChartView.delegate = self; [self.m_pieContainer addSubview:self.m_pieChartView]; [self.m_pieChartView reloadChart]; if (self.inOut) { [self.m_pieChartView setTitleText:@"支出总计"]; [self.m_pieChartView setAmountText:@"-2456.0"]; }else{ [self.m_pieChartView setTitleText:@"收入总计"]; [self.m_pieChartView setAmountText:@"+567.23"]; }}- (void)viewDidAppear:(BOOL)animated{ [self.m_pieChartView reloadChart];}- (void)didReceiveMemoryWarning{ [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated.}@end
0 0
- iOS可旋转的饼图
- iOS 可旋转的Chart 饼图
- Cocos2d-x3.0 可旋转的饼图
- iOS 指定部分页面可屏幕旋转
- iOS使用UICollectionView实现可旋转菜单
- iOS编程——Swift实现一个3D可旋转的立方体(可做菜单页)
- [iOS]图组全屏可缩放和旋转屏幕来展示
- iOS View的旋转
- javascript可控制的螺旋式旋转菜单
- javascript可控制的螺旋式旋转菜单
- anroid:自定义可旋转的TextView控件
- 使用GDI+ 绘制可旋转的PNG
- Android 可平移,缩放,旋转的ImageView
- opengles绘制可旋转的六角星
- opengles绘制可旋转的球体
- 如何实现一个可旋转的TextView
- Android之可旋转的轮盘菜单
- 自定义可旋转的Label控件
- Eclipse中常用的快捷键和模板配置
- 76运输机观测到白色漂浮物
- 开发随笔-Oracle数据库-----死锁
- linux下discuz出现数据库链接错误
- 一同分享亲子刹那 赢取缤纷大奖
- iOS可旋转的饼图
- linux下配置JDK环境变量
- django操作数据库例子
- 受打击
- 使用RPM包管理命令的笔记
- linux 8080端口占用
- Android--Apache HttpClient
- Android3D绘图之OpenGL ES(四)
- git学习四(远程分支)