登录 立即注册
金钱:

Code4App-iOS开发-iOS 开源代码库-iOS代码实例搜索-iOS特效示例-iOS代码例子下载-Code4App.com

圆形统计图 KKCirStatisticalFigure

[复制链接]
来自: kukela 分类: iOS精品源码 上传时间: 2016-6-15 17:43:48
Tag:图表 圆形统计图 charts 图形 统计图

项目介绍:

一个带解释标签的圆形统计图,可调整演示标签的出现速度。
主要实现代码:
[Objective-C] 查看源文件 复制代码
#import "ViewController.h"
#import "KKCirStatisticalFigureView.h"
#import "NSTimer+KKTools.h"

@interface ViewController () <UIActionSheetDelegate>

@property (weak, nonatomic) IBOutlet KKCirStatisticalFigureView *cirStatisticalFigureView;
@property (weak, nonatomic) IBOutlet UISlider *speedSlider;
@property (weak, nonatomic) IBOutlet UIButton *stopButton;

@end

@implementation ViewController{
    NSTimer *testDataTimer;
    CGFloat speed;
    BOOL isStopTestDataTimer;
    NSInteger testStyle;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    [self initView];
    [NSThread detachNewThreadSelector:@selector(testData) toTarget:self withObject:nil];
}

#pragma mark - Init

-(void)initView{
    self.cirStatisticalFigureView.backgroundColor = [UIColor clearColor];
    self.cirStatisticalFigureView.edgeInsets = UIEdgeInsetsMake(10, 10, 10, 10);
    self.cirStatisticalFigureView.isAdapter = YES;
    speed = 0.1f;
    testStyle = 1;
    [self.speedSlider setValue:speed animated:YES];
    
//    self.cirStatisticalFigureView.percentageArray = @[@104, @2, @5, @1, @4];
//    self.cirStatisticalFigureView.startAngle = 1.413717;
//    self.cirStatisticalFigureView.isClockwise = NO;
}

#pragma mark - Data

-(void)testData{
    testDataTimer = [NSTimer kkScheduledTimerWithTimeInterval:speed block:^{
        
        NSArray *percentageArray = [self randomPerentageArrayWithStyle:testStyle];
        CGFloat startAngle = [self randomAngle];
        BOOL isClockwise = arc4random() % 2;
        
        self.cirStatisticalFigureView.percentageArray = percentageArray;
        self.cirStatisticalFigureView.startAngle = startAngle;
        self.cirStatisticalFigureView.isClockwise = isClockwise;
        
        NSMutableString *percentageArrayMS = [NSMutableString string];
        for (NSInteger i = 0; i < percentageArray.count; i++) {
            if (!i) {
                [percentageArrayMS appendString:@"@["];
            }
            NSString *percentageString = [NSString stringWithFormat:@"@%ld", [percentageArray[i] integerValue]];
            [percentageArrayMS appendString:percentageString];
            if (i == percentageArray.count - 1) {
                [percentageArrayMS appendString:@"];"];
            }else{
                [percentageArrayMS appendString:@", "];
            }
        }
        
        NSLog(@"%f %@", startAngle, isClockwise ? @"YES" : @"NO");
        NSLog(@"%@", percentageArrayMS);
        
        NSLog(@"------------------------------------------------------ ");
    } repeats:YES];
    [testDataTimer fire];
    [[NSRunLoop currentRunLoop] run];
}

#pragma mark - Button

- (IBAction)button:(UIButton *)sender {
    switch (sender.tag) {
        case 0:{
            isStopTestDataTimer = !isStopTestDataTimer;
            NSString *buttonTitle = nil;
            if (isStopTestDataTimer) {
                [testDataTimer setFireDate:[NSDate distantFuture]];
                buttonTitle = @"开始";
            }else{
                [testDataTimer setFireDate:[NSDate date]];
                buttonTitle = @"暂停";
            }
            [sender setTitle:buttonTitle forState:UIControlStateNormal];
            break;
        }
        case 1:{
            [testDataTimer setFireDate:[NSDate distantFuture]];
            UIActionSheet *actionSheet = [[UIActionSheet alloc]initWithTitle:nil
                                                                    delegate:self
                                                           cancelButtonTitle:@"取消"
                                                      destructiveButtonTitle:nil
                                                           otherButtonTitles:nil];
            actionSheet.actionSheetStyle = UIActionSheetStyleDefault;
            for (NSInteger i = 0; i <= 6; i++) {
                [actionSheet addButtonWithTitle:[NSString stringWithFormat:@"样式 %ld", (long)i]];
            }
            [actionSheet showInView:self.view];
            break;
        }
        default:
            break;
    }
}

#pragma mark - UISlider

- (IBAction)sliderTouchDown:(UISlider *)sender {
    isStopTestDataTimer = NO;
    [self.stopButton setTitle:@"暂停" forState:UIControlStateNormal];
}

- (IBAction)sliderChanged:(UISlider *)sender {
    speed = sender.value;
    [testDataTimer invalidate];
    testDataTimer = nil;
    [NSThread detachNewThreadSelector:@selector(testData) toTarget:self withObject:nil];
}

#pragma mark - UIActionSheet

-(void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex{
    testStyle = buttonIndex - 1;
    [testDataTimer setFireDate:[NSDate date]];
}

#pragma mark - Private

#define ONE_ANGLE_PI 0.01745329251994329547437168059786927
-(CGFloat)randomAngle{
    NSInteger angleDegreeRandom = arc4random() % 381;
    CGFloat angle = angleDegreeRandom * ONE_ANGLE_PI;
    return angle;
}

-(NSArray *)randomPerentageArrayWithStyle:(NSInteger)style{
    NSMutableArray *percentageMArray = [NSMutableArray array];
    switch (style) {
        case 0:{
            for (NSInteger i = 0; i < 5; i++) {
                NSInteger percentage = arc4random() % 100 + 1;
                [percentageMArray addObject:@(percentage)];
            }
            break;
        }
        case 1:{
            for (NSInteger i = 0; i < 5; i++) {
                NSInteger percentage = 0;
                if (i) {
                    percentage = arc4random() % 7 + 1;
                }else{
                    percentage = arc4random() % 120 + 1;
                }
                [percentageMArray addObject:@(percentage)];
            }
            break;
        }
        case 2:{
            for (NSInteger i = 0; i < 15; i++) {
                NSInteger percentage = arc4random() % 100 + 1;
                [percentageMArray addObject:@(percentage)];
            }
            break;
        }
        case 3:{
            NSInteger percentageNumber = arc4random() % 15 + 1;
            for (NSInteger i = 0; i < percentageNumber; i++) {
                NSInteger percentage = arc4random() % 100 + 1;
                [percentageMArray addObject:@(percentage)];
            }
            break;
        }
        case 4:{
            NSInteger percentageNumber = arc4random() % 15 + 1;
            for (NSInteger i = 0; i < percentageNumber; i++) {
                NSInteger percentage = 0;
                if (i) {
                    percentage = arc4random() % 7 + 1;
                }else{
                    percentage = arc4random() % 150 + 1;
                }
                [percentageMArray addObject:@(percentage)];
            }
            break;
        }
        case 5:{
            NSInteger percentageNumber = arc4random() % 35 + 1;
            for (NSInteger i = 0; i < percentageNumber; i++) {
                NSInteger percentage = 0;
                if (i) {
                    percentage = arc4random() % 7 + 1;
                }else{
                    percentage = arc4random() % 50 + 1;
                }
                [percentageMArray addObject:@(percentage)];
            }
            break;
        }
        case 6:{
            NSInteger percentageNumber = arc4random() % 100 + 1;
            for (NSInteger i = 0; i < percentageNumber; i++) {
                NSInteger percentage = 0;
                if (i) {
                    percentage = arc4random() % 7 + 1;
                }else{
                    percentage = arc4random() % 50 + 1;
                }
                [percentageMArray addObject:@(percentage)];
            }
            break;
        }
        default:
            break;
    }
    return percentageMArray;
}


@end






2016_4_22_12.53.05.png

2016-04-22_10_26_30.gif 2016-04-22_10_29_53.gif


DEMO直接下载:

相关源码推荐:

我来说两句
*滑动验证:
所有评论(83)
inremembert 2016-6-15 20:17:03
很给力,Code4App有你更精彩!
回复
liujinfeng 2016-6-16 09:28:56
很给力,Code4App有你更精彩!
回复
王颖博 2016-6-16 09:59:35
很给力,Code4App有你更精彩!
回复
初冬 2016-6-16 10:07:00
楼主用心了,内容非常精彩。
回复
gyhgyg 2016-6-16 13:47:40
学习学习!
回复
0123456789ooooo 2016-6-16 14:12:14
感谢分享,Code4App有你更精彩
回复
jingelaile 2016-6-16 14:28:34
正需要啊,感谢楼主无私分享!
回复
startlive 2016-6-16 17:39:55
code4app有你更精彩!
回复
leonlee723 2016-6-16 17:40:16
谢谢大神,谢谢你的分享!
回复
提取码:  下载次数:61 状态:已购或VIP 售价:0(原价:10)金钱 下载权限:初级码农 
1633 0 61
联系我们
首页/微信公众账号投稿

帖子代码编辑/版权问题

QQ:435399051,742864542

如何获得代码达人称号?

代码贡献英雄榜
用户名 下载数
通过邮件订阅最新 Code4App 信息
上一条 /4 下一条
联系我们
关闭
合作电话:
13802416937
Email:
435399051@qq.com
商务市场合作/投稿
问题反馈及帮助
联系我们

广告投放| Github|申请友链|手机版|Code4App ( 粤ICP备15117877号-1 )

快速回复 返回顶部 返回列表