Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- - (void)viewWillAppear:(BOOL)animated {
- CGRect watchersRect = CGRectMake(0, 20, 320, 460);
- UIView *colorLayer = [[UIView alloc]initWithFrame:watchersRect];
- colorLayer.backgroundColor = [UIColor grayColor];
- [self.view addSubview:colorLayer];
- UIStackView *watchersUI = [[UIStackView alloc]init];
- NSMutableArray *leftArr=[[NSMutableArray alloc]init];
- NSMutableArray *rightArr=[[NSMutableArray alloc]init];
- NSMutableArray *yearStackUIArr = [[NSMutableArray alloc]initWithObjects:@"year 1", @"year2",@"year3",@"year4",@"year5",nil];
- NSMutableArray *monthStackUIArr = [[NSMutableArray alloc]initWithObjects:@"month 1", @"month 2",@"month 3",nil];
- NSMutableArray *dayStackUIArr = [[NSMutableArray alloc]initWithObjects:@"day1", @"day2",@"day3",nil];
- watchersUI = [[UIStackView alloc] initWithFrame:watchersRect];
- watchersUI.axis= UILayoutConstraintAxisHorizontal;
- watchersUI.distribution = UIStackViewDistributionFillEqually;
- watchersUI.alignment = UIStackViewAlignmentFill;
- watchersUI.spacing = 2;
- watchersUI.translatesAutoresizingMaskIntoConstraints = YES;
- [colorLayer addSubview:watchersUI];
- UIView *leftColumn = [[UIView alloc] init];
- [leftColumn setBackgroundColor:[UIColor yellowColor]];
- UIView *rightColumn = [[UIView alloc]init];
- [rightColumn setBackgroundColor:[UIColor redColor]];
- [watchersUI addArrangedSubview:leftColumn];
- [watchersUI addArrangedSubview:rightColumn];
- [leftColumn.leftAnchor constraintEqualToAnchor:watchersUI.leftAnchor].active = YES;
- [rightColumn.rightAnchor constraintEqualToAnchor:watchersUI.rightAnchor].active = YES;
- [leftColumn.bottomAnchor constraintEqualToAnchor:watchersUI.bottomAnchor].active = YES;
- [rightColumn.bottomAnchor constraintEqualToAnchor:watchersUI.bottomAnchor].active = YES;
- UIStackView *leftStack =[[UIStackView alloc]init];
- leftStack.axis = UILayoutConstraintAxisVertical;
- leftStack.distribution = UIStackViewDistributionEqualSpacing;
- leftStack.alignment=UIStackViewAlignmentFill;
- leftStack.spacing =1;
- leftStack.translatesAutoresizingMaskIntoConstraints = NO;
- [leftColumn addSubview:leftStack];
- UIStackView *rightStack =[[UIStackView alloc]init];
- rightStack.axis = UILayoutConstraintAxisVertical;
- rightStack.distribution = UIStackViewDistributionFillProportionally;
- rightStack.alignment=UIStackViewAlignmentLeading;
- rightStack.spacing =2;
- rightStack.translatesAutoresizingMaskIntoConstraints = NO;
- [rightColumn addSubview:rightStack];
- if ([yearStackUIArr count]>0) {
- UIView *yearBox=[[UIView alloc]init];
- yearBox.backgroundColor = [UIColor purpleColor];
- NSLog(@"year leftArr %d",[leftArr count]);
- NSLog(@"year rightArr %d",[rightArr count]);
- if ([rightArr count]<[leftArr count]) {
- [rightStack addArrangedSubview:yearBox];
- [rightArr addObject:yearBox];
- [NSLayoutConstraint constraintWithItem:yearBox attribute:NSLayoutAttributeHeight relatedBy:NSLayoutRelationLessThanOrEqual toItem:rightStack attribute:NSLayoutAttributeHeight multiplier:1 constant:0].active = YES;
- UILayoutGuide *margin = rightStack.layoutMarginsGuide;
- [yearBox.heightAnchor constraintLessThanOrEqualToAnchor:margin.heightAnchor].active =YES;
- [yearBox.topAnchor constraintEqualToAnchor:rightColumn.topAnchor].active = YES;
- [yearBox.leftAnchor constraintEqualToAnchor:rightColumn.leftAnchor].active = YES;
- [yearBox.rightAnchor constraintEqualToAnchor:rightColumn.rightAnchor].active = YES;
- }
- else if(([rightArr count]==[leftArr count])||([rightArr count]>[leftArr count]))
- {
- [leftStack addArrangedSubview:yearBox];
- [leftArr addObject:yearBox];
- for (UIView *subs in leftStack.subviews) {
- NSLog(@"yearBox leftStack %@",subs);
- }
- [NSLayoutConstraint constraintWithItem:yearBox attribute:NSLayoutAttributeHeight relatedBy:NSLayoutRelationLessThanOrEqual toItem:leftStack attribute:NSLayoutAttributeHeight multiplier:1 constant:0].active=YES;
- UILayoutGuide *margin = leftStack.layoutMarginsGuide;
- [yearBox.heightAnchor constraintLessThanOrEqualToAnchor:margin.heightAnchor].active = YES;
- [yearBox.topAnchor constraintEqualToAnchor:leftColumn.topAnchor].active = YES;
- [yearBox.leftAnchor constraintEqualToAnchor:leftColumn.leftAnchor].active = YES;
- [yearBox.rightAnchor constraintEqualToAnchor:leftColumn.rightAnchor].active = YES;
- }
- UIStackView *boxStack = [[UIStackView alloc]init];
- boxStack.axis = UILayoutConstraintAxisVertical;
- boxStack.distribution = UIStackViewDistributionFillEqually;
- boxStack.alignment=UIStackViewAlignmentLeading;
- boxStack.spacing=1;
- boxStack.translatesAutoresizingMaskIntoConstraints = NO;
- [yearBox addSubview:boxStack];
- for (NSString *innerItem in yearStackUIArr) {
- UILabel *innerView = [[UILabel alloc]init];
- [boxStack addArrangedSubview:innerView];
- [innerView.leftAnchor constraintEqualToAnchor:yearBox.leftAnchor].active =YES;
- [innerView.rightAnchor constraintEqualToAnchor:yearBox.rightAnchor].active =YES;
- [innerView.heightAnchor constraintGreaterThanOrEqualToConstant:20].active =YES;
- innerView.backgroundColor =[UIColor cyanColor];
- innerView.text = innerItem;
- innerView.font = [UIFont systemFontOfSize:10];
- }
- }
- if ([monthStackUIArr count]>0) {
- UIView *monthBox=[[UIView alloc]init];
- monthBox.backgroundColor =[UIColor blackColor];
- if ([rightArr count]<[leftArr count]) {
- [rightStack addArrangedSubview:monthBox];
- [rightArr addObject:monthBox];
- [NSLayoutConstraint constraintWithItem:monthBox attribute:NSLayoutAttributeHeight relatedBy:NSLayoutRelationLessThanOrEqual toItem:rightStack attribute:NSLayoutAttributeHeight multiplier:1 constant:0].active = YES;
- UILayoutGuide *margin = rightStack.layoutMarginsGuide;
- [monthBox.heightAnchor constraintLessThanOrEqualToAnchor:margin.heightAnchor].active =YES;
- [monthBox.leftAnchor constraintEqualToAnchor:rightColumn.leftAnchor].active = YES;
- [monthBox.rightAnchor constraintEqualToAnchor:rightColumn.rightAnchor].active = YES;
- }
- else if(([rightArr count]==[leftArr count])||([rightArr count]>[leftArr count]))
- {
- [leftStack addArrangedSubview:monthBox];
- [leftArr addObject:monthBox];
- [NSLayoutConstraint constraintWithItem:monthBox attribute:NSLayoutAttributeHeight relatedBy:NSLayoutRelationLessThanOrEqual toItem:leftStack attribute:NSLayoutAttributeHeight multiplier:1 constant:0].active = YES;
- UILayoutGuide *margin = leftStack.layoutMarginsGuide;
- [monthBox.heightAnchor constraintLessThanOrEqualToAnchor:margin.heightAnchor].active =YES;
- [monthBox.leftAnchor constraintEqualToAnchor:leftColumn.leftAnchor].active = YES;
- [monthBox.rightAnchor constraintEqualToAnchor:leftColumn.rightAnchor].active = YES;
- }
- UIStackView *boxStack = [[UIStackView alloc]init];
- boxStack.axis = UILayoutConstraintAxisVertical;
- boxStack.distribution = UIStackViewDistributionFillEqually;
- boxStack.alignment=UIStackViewAlignmentLeading;
- boxStack.spacing=2;
- boxStack.translatesAutoresizingMaskIntoConstraints = NO;
- [monthBox addSubview:boxStack];
- for (NSString *innerItem in monthStackUIArr) {
- UILabel *innerView = [[UILabel alloc]init];
- [boxStack addArrangedSubview:innerView];
- [innerView.leftAnchor constraintEqualToAnchor:monthBox.leftAnchor].active =YES;
- [innerView.rightAnchor constraintEqualToAnchor:monthBox.rightAnchor].active =YES;
- [innerView.heightAnchor constraintGreaterThanOrEqualToConstant:20].active =YES;
- innerView.backgroundColor =[UIColor whiteColor];
- innerView.text = innerItem;
- innerView.font = [UIFont systemFontOfSize:10];
- }
- }
- if ([dayStackUIArr count]>0) {
- UIView *dayBox=[[UIView alloc]init];
- dayBox.backgroundColor =[UIColor brownColor];
- if ([rightArr count]<[leftArr count]) {
- [rightStack addArrangedSubview:dayBox];
- [rightArr addObject:dayBox];
- [NSLayoutConstraint constraintWithItem:dayBox attribute:NSLayoutAttributeHeight relatedBy:NSLayoutRelationLessThanOrEqual toItem:rightStack attribute:NSLayoutAttributeHeight multiplier:1 constant:0].active = YES;
- UILayoutGuide *margin = rightStack.layoutMarginsGuide;
- [dayBox.heightAnchor constraintGreaterThanOrEqualToAnchor:margin.heightAnchor].active =YES;
- [dayBox.leftAnchor constraintEqualToAnchor:rightColumn.leftAnchor].active = YES;
- [dayBox.rightAnchor constraintEqualToAnchor:rightColumn.rightAnchor].active = YES;
- if ([rightArr count]>0) {
- UIView *tmpbox = rightArr[[rightArr count]-2];
- [dayBox.topAnchor constraintEqualToAnchor:tmpbox.bottomAnchor].active=YES;
- }
- }
- else if(([rightArr count]==[leftArr count])||([rightArr count]>[leftArr count]))
- {
- [leftStack addArrangedSubview:dayBox];
- [leftArr addObject:dayBox];
- [NSLayoutConstraint constraintWithItem:dayBox attribute:NSLayoutAttributeHeight relatedBy:NSLayoutRelationLessThanOrEqual toItem:leftStack attribute:NSLayoutAttributeHeight multiplier:1 constant:0].active = YES;
- UILayoutGuide *margin = leftStack.layoutMarginsGuide;
- [dayBox.heightAnchor constraintGreaterThanOrEqualToAnchor:margin.heightAnchor].active =YES;
- [dayBox.leftAnchor constraintEqualToAnchor:leftColumn.leftAnchor].active = YES;
- [dayBox.rightAnchor constraintEqualToAnchor:leftColumn.rightAnchor].active = YES;
- }
- UIStackView *boxStack = [[UIStackView alloc]init];
- boxStack.axis = UILayoutConstraintAxisVertical;
- boxStack.distribution = UIStackViewDistributionFillEqually;
- boxStack.alignment=UIStackViewAlignmentLeading;
- boxStack.spacing=2;
- boxStack.translatesAutoresizingMaskIntoConstraints = NO;
- [dayBox addSubview:boxStack];
- for (NSString *innerItem in dayStackUIArr) {
- UILabel *innerView = [[UILabel alloc]init];
- [boxStack addArrangedSubview:innerView];
- [innerView.leftAnchor constraintEqualToAnchor:dayBox.leftAnchor].active =YES;
- [innerView.rightAnchor constraintEqualToAnchor:dayBox.rightAnchor].active =YES;
- [innerView.heightAnchor constraintGreaterThanOrEqualToConstant:20].active =YES;
- innerView.backgroundColor =[UIColor blueColor];
- innerView.text = innerItem;
- innerView.font = [UIFont systemFontOfSize:10];
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement