利用for画出树状图

这图 其实利用storyboard画出来更加方便


利用for画出树状图_第1张图片
效果图
#pragma vitamin
UIView *vitamin= [[UIView alloc]initWithFrame:CGRectMake(0, kWidth(793) , kScreenWidth, 180)];
vitamin.backgroundColor = kWhiteColor;
[_contentScrollView addSubview:vitamin];

orangeLine = [[UIView alloc]initWithFrame:CGRectMake(kWidth(10), kHeight(7), kWidth(2), kHeight(15))];
orangeLine.backgroundColor = UIColorFromRGB(0xfd560b);
[vitamin addSubview:orangeLine];

UILabel *labvitamin = [[UILabel alloc]initWithFrame:CGRectMake(kWidth(20), kHeight(7), kWidth(200), kHeight(15))];
labvitamin.text =@"维生素(umg)";
[vitamin addSubview:labvitamin];


for(NSInteger i = 0 ; i<100 ;i++){
    UIView *vitaminlinein = [[UIView alloc]initWithFrame:CGRectMake(kWidth(35)+kWidth( 3.5*i),kScreenWidth-kWidth(70), kHeight(198), 0.5)];
    vitaminlinein.backgroundColor = UIColorFromRGB(0x9ea1a0);
    [vitamin addSubview:vitaminlinein];

}

NSArray *letters = [[NSArray alloc ]initWithObjects:@"A",@"B",@"C",@"D",@"E",nil];



for (int i = 0 ; i<5; i++) {
    UIView *vitaminPoin = [[UIView alloc]init];
    UIView *vitaminRectangle = [[UIView alloc]init];
    UILabel *vitaminlabNumber = [[UILabel alloc]init];
    UILabel *vitaminlabName = [[UILabel alloc]init];
    
    vitaminPoin.frame = CGRectMake(
                                        kWidth(55)+(i *kWidth(50)),
                                        kHeight(150),
                                        kWidth(10),
                                        kHeight(10) );
    vitaminPoin.layer.cornerRadius = 5;
    vitaminPoin.backgroundColor = ArrayColo[i];

    
    
    vitaminRectangle.frame = CGRectMake(
                                             kWidth(53)+(i *kWidth(50)),
                                             kHeight(40),
                                             kWidth(15),
                                             kHeight(104) );
    vitaminRectangle.backgroundColor = ArrayColo[i];
    
    vitaminlabNumber.frame = CGRectMake((vitaminRectangle.bounds.origin.x + kWidth(45)) + i *kWidth(50), vitaminRectangle.bounds.origin.y + kHeight(25), kWidth(35), kHeight(15));
    vitaminlabNumber.backgroundColor = UIColorFromRGB(0xf0eef4);
    vitaminlabNumber.text =@"1500";
    vitaminlabNumber.font=[UIFont systemFontOfSize:12];
    vitaminlabNumber.textAlignment = NSTextAlignmentCenter;
    
    vitaminlabName.frame = CGRectMake(kWidth(50)+(i *kWidth(50)),kHeight(160),kWidth(20), kHeight(20));
    
    vitaminlabName.backgroundColor = UIColorFromRGB(0xf0eef4);
    vitaminlabName.text =letters[i];
    vitaminlabName.textColor = ArrayColo[i];
    vitaminlabName.font=[UIFont systemFontOfSize:12];
    vitaminlabName.textAlignment = NSTextAlignmentCenter;
    vitaminlabName .backgroundColor = kClearColor;
    
    [vitamin addSubview:vitaminPoin];
    [vitamin addSubview:vitaminRectangle];
    [vitamin addSubview:vitaminlabNumber];
    [vitamin addSubview:vitaminlabName];
    
}

你可能感兴趣的:(利用for画出树状图)