开始的效果图:
点击饼图后,饼图会转一下,同时左下角显示文字,效果图:
项目架构图,注意此项目是要导入第三方库pieChat的,里面包括两个文件,PieChartView.h.PieChartView.m
RootViewControler.m
- (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view. NSMutableArray *valueArray = [[NSMutableArray alloc] initWithObjects: [NSNumber numberWithInt:1], [NSNumber numberWithInt:1], [NSNumber numberWithInt:1], [NSNumber numberWithInt:3], [NSNumber numberWithInt:2], nil]; NSMutableArray *colorArray = [[NSMutableArray alloc] initWithObjects: [UIColor blueColor], [UIColor redColor], [UIColor orangeColor], [UIColor greenColor], [UIColor purpleColor], nil]; // 必须先创建一个相同大小的container view,再将PieChartView add上去 UIView *container = [[UIView alloc] initWithFrame:CGRectMake((320 - 250) / 2, 90, 250, 250)]; PieChartView* pieView = [[PieChartView alloc] initWithFrame:CGRectMake(0, 0, 250, 250)]; [container addSubview:pieView]; pieView.mValueArray = [NSMutableArray arrayWithArray:valueArray]; pieView.mColorArray = [NSMutableArray arrayWithArray:colorArray]; pieView.mInfoTextView = [[UITextView alloc] initWithFrame:CGRectMake(20, 350, 300, 80)]; pieView.mInfoTextView.backgroundColor = [UIColor clearColor]; pieView.mInfoTextView.editable = NO; pieView.mInfoTextView.userInteractionEnabled = NO; [self.view addSubview:container]; [self.view addSubview:pieView.mInfoTextView]; }