Advertisement
Guest User

Untitled

a guest
May 28th, 2016
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.26 KB | None | 0 0
  1. - (void)viewWillAppear:(BOOL)animated {
  2. CGRect watchersRect = CGRectMake(0, 20, 320, 460);
  3. UIView *colorLayer = [[UIView alloc]initWithFrame:watchersRect];
  4. colorLayer.backgroundColor = [UIColor grayColor];
  5.  
  6. [self.view addSubview:colorLayer];
  7.  
  8.  
  9. UIStackView *watchersUI = [[UIStackView alloc]init];
  10. NSMutableArray *leftArr=[[NSMutableArray alloc]init];
  11. NSMutableArray *rightArr=[[NSMutableArray alloc]init];
  12.  
  13. NSMutableArray *yearStackUIArr = [[NSMutableArray alloc]initWithObjects:@"year 1", @"year2",@"year3",@"year4",@"year5",nil];
  14. NSMutableArray *monthStackUIArr = [[NSMutableArray alloc]initWithObjects:@"month 1", @"month 2",@"month 3",nil];
  15. NSMutableArray *dayStackUIArr = [[NSMutableArray alloc]initWithObjects:@"day1", @"day2",@"day3",nil];
  16.  
  17.  
  18.  
  19. watchersUI = [[UIStackView alloc] initWithFrame:watchersRect];
  20. watchersUI.axis= UILayoutConstraintAxisHorizontal;
  21. watchersUI.distribution = UIStackViewDistributionFillEqually;
  22. watchersUI.alignment = UIStackViewAlignmentFill;
  23. watchersUI.spacing = 2;
  24. watchersUI.translatesAutoresizingMaskIntoConstraints = YES;
  25.  
  26. [colorLayer addSubview:watchersUI];
  27.  
  28.  
  29. UIView *leftColumn = [[UIView alloc] init];
  30. [leftColumn setBackgroundColor:[UIColor yellowColor]];
  31.  
  32. UIView *rightColumn = [[UIView alloc]init];
  33. [rightColumn setBackgroundColor:[UIColor redColor]];
  34.  
  35.  
  36. [watchersUI addArrangedSubview:leftColumn];
  37. [watchersUI addArrangedSubview:rightColumn];
  38.  
  39. [leftColumn.leftAnchor constraintEqualToAnchor:watchersUI.leftAnchor].active = YES;
  40. [rightColumn.rightAnchor constraintEqualToAnchor:watchersUI.rightAnchor].active = YES;
  41. [leftColumn.bottomAnchor constraintEqualToAnchor:watchersUI.bottomAnchor].active = YES;
  42. [rightColumn.bottomAnchor constraintEqualToAnchor:watchersUI.bottomAnchor].active = YES;
  43.  
  44.  
  45. UIStackView *leftStack =[[UIStackView alloc]init];
  46. leftStack.axis = UILayoutConstraintAxisVertical;
  47. leftStack.distribution = UIStackViewDistributionEqualSpacing;
  48. leftStack.alignment=UIStackViewAlignmentFill;
  49. leftStack.spacing =1;
  50. leftStack.translatesAutoresizingMaskIntoConstraints = NO;
  51.  
  52. [leftColumn addSubview:leftStack];
  53.  
  54.  
  55. UIStackView *rightStack =[[UIStackView alloc]init];
  56. rightStack.axis = UILayoutConstraintAxisVertical;
  57. rightStack.distribution = UIStackViewDistributionFillProportionally;
  58. rightStack.alignment=UIStackViewAlignmentLeading;
  59. rightStack.spacing =2;
  60. rightStack.translatesAutoresizingMaskIntoConstraints = NO;
  61. [rightColumn addSubview:rightStack];
  62.  
  63.  
  64.  
  65.  
  66.  
  67.  
  68. if ([yearStackUIArr count]>0) {
  69. UIView *yearBox=[[UIView alloc]init];
  70. yearBox.backgroundColor = [UIColor purpleColor];
  71.  
  72. NSLog(@"year leftArr %d",[leftArr count]);
  73. NSLog(@"year rightArr %d",[rightArr count]);
  74.  
  75. if ([rightArr count]<[leftArr count]) {
  76.  
  77. [rightStack addArrangedSubview:yearBox];
  78. [rightArr addObject:yearBox];
  79. [NSLayoutConstraint constraintWithItem:yearBox attribute:NSLayoutAttributeHeight relatedBy:NSLayoutRelationLessThanOrEqual toItem:rightStack attribute:NSLayoutAttributeHeight multiplier:1 constant:0].active = YES;
  80. UILayoutGuide *margin = rightStack.layoutMarginsGuide;
  81. [yearBox.heightAnchor constraintLessThanOrEqualToAnchor:margin.heightAnchor].active =YES;
  82.  
  83. [yearBox.topAnchor constraintEqualToAnchor:rightColumn.topAnchor].active = YES;
  84. [yearBox.leftAnchor constraintEqualToAnchor:rightColumn.leftAnchor].active = YES;
  85. [yearBox.rightAnchor constraintEqualToAnchor:rightColumn.rightAnchor].active = YES;
  86.  
  87.  
  88.  
  89. }
  90. else if(([rightArr count]==[leftArr count])||([rightArr count]>[leftArr count]))
  91. {
  92. [leftStack addArrangedSubview:yearBox];
  93. [leftArr addObject:yearBox];
  94.  
  95. for (UIView *subs in leftStack.subviews) {
  96. NSLog(@"yearBox leftStack %@",subs);
  97. }
  98.  
  99. [NSLayoutConstraint constraintWithItem:yearBox attribute:NSLayoutAttributeHeight relatedBy:NSLayoutRelationLessThanOrEqual toItem:leftStack attribute:NSLayoutAttributeHeight multiplier:1 constant:0].active=YES;
  100. UILayoutGuide *margin = leftStack.layoutMarginsGuide;
  101. [yearBox.heightAnchor constraintLessThanOrEqualToAnchor:margin.heightAnchor].active = YES;
  102.  
  103.  
  104. [yearBox.topAnchor constraintEqualToAnchor:leftColumn.topAnchor].active = YES;
  105. [yearBox.leftAnchor constraintEqualToAnchor:leftColumn.leftAnchor].active = YES;
  106. [yearBox.rightAnchor constraintEqualToAnchor:leftColumn.rightAnchor].active = YES;
  107.  
  108.  
  109. }
  110.  
  111.  
  112. UIStackView *boxStack = [[UIStackView alloc]init];
  113. boxStack.axis = UILayoutConstraintAxisVertical;
  114. boxStack.distribution = UIStackViewDistributionFillEqually;
  115. boxStack.alignment=UIStackViewAlignmentLeading;
  116. boxStack.spacing=1;
  117. boxStack.translatesAutoresizingMaskIntoConstraints = NO;
  118. [yearBox addSubview:boxStack];
  119.  
  120. for (NSString *innerItem in yearStackUIArr) {
  121. UILabel *innerView = [[UILabel alloc]init];
  122. [boxStack addArrangedSubview:innerView];
  123.  
  124. [innerView.leftAnchor constraintEqualToAnchor:yearBox.leftAnchor].active =YES;
  125. [innerView.rightAnchor constraintEqualToAnchor:yearBox.rightAnchor].active =YES;
  126. [innerView.heightAnchor constraintGreaterThanOrEqualToConstant:20].active =YES;
  127. innerView.backgroundColor =[UIColor cyanColor];
  128. innerView.text = innerItem;
  129. innerView.font = [UIFont systemFontOfSize:10];
  130.  
  131.  
  132. }
  133.  
  134. }
  135.  
  136.  
  137.  
  138. if ([monthStackUIArr count]>0) {
  139. UIView *monthBox=[[UIView alloc]init];
  140. monthBox.backgroundColor =[UIColor blackColor];
  141.  
  142.  
  143. if ([rightArr count]<[leftArr count]) {
  144. [rightStack addArrangedSubview:monthBox];
  145. [rightArr addObject:monthBox];
  146.  
  147. [NSLayoutConstraint constraintWithItem:monthBox attribute:NSLayoutAttributeHeight relatedBy:NSLayoutRelationLessThanOrEqual toItem:rightStack attribute:NSLayoutAttributeHeight multiplier:1 constant:0].active = YES;
  148. UILayoutGuide *margin = rightStack.layoutMarginsGuide;
  149. [monthBox.heightAnchor constraintLessThanOrEqualToAnchor:margin.heightAnchor].active =YES;
  150.  
  151. [monthBox.leftAnchor constraintEqualToAnchor:rightColumn.leftAnchor].active = YES;
  152. [monthBox.rightAnchor constraintEqualToAnchor:rightColumn.rightAnchor].active = YES;
  153.  
  154. }
  155. else if(([rightArr count]==[leftArr count])||([rightArr count]>[leftArr count]))
  156. {
  157. [leftStack addArrangedSubview:monthBox];
  158. [leftArr addObject:monthBox];
  159.  
  160. [NSLayoutConstraint constraintWithItem:monthBox attribute:NSLayoutAttributeHeight relatedBy:NSLayoutRelationLessThanOrEqual toItem:leftStack attribute:NSLayoutAttributeHeight multiplier:1 constant:0].active = YES;
  161. UILayoutGuide *margin = leftStack.layoutMarginsGuide;
  162. [monthBox.heightAnchor constraintLessThanOrEqualToAnchor:margin.heightAnchor].active =YES;
  163.  
  164. [monthBox.leftAnchor constraintEqualToAnchor:leftColumn.leftAnchor].active = YES;
  165. [monthBox.rightAnchor constraintEqualToAnchor:leftColumn.rightAnchor].active = YES;
  166. }
  167.  
  168. UIStackView *boxStack = [[UIStackView alloc]init];
  169. boxStack.axis = UILayoutConstraintAxisVertical;
  170. boxStack.distribution = UIStackViewDistributionFillEqually;
  171. boxStack.alignment=UIStackViewAlignmentLeading;
  172. boxStack.spacing=2;
  173. boxStack.translatesAutoresizingMaskIntoConstraints = NO;
  174. [monthBox addSubview:boxStack];
  175.  
  176. for (NSString *innerItem in monthStackUIArr) {
  177. UILabel *innerView = [[UILabel alloc]init];
  178. [boxStack addArrangedSubview:innerView];
  179.  
  180. [innerView.leftAnchor constraintEqualToAnchor:monthBox.leftAnchor].active =YES;
  181. [innerView.rightAnchor constraintEqualToAnchor:monthBox.rightAnchor].active =YES;
  182. [innerView.heightAnchor constraintGreaterThanOrEqualToConstant:20].active =YES;
  183. innerView.backgroundColor =[UIColor whiteColor];
  184. innerView.text = innerItem;
  185. innerView.font = [UIFont systemFontOfSize:10];
  186.  
  187. }
  188.  
  189.  
  190.  
  191. }
  192.  
  193. if ([dayStackUIArr count]>0) {
  194. UIView *dayBox=[[UIView alloc]init];
  195. dayBox.backgroundColor =[UIColor brownColor];
  196.  
  197.  
  198. if ([rightArr count]<[leftArr count]) {
  199.  
  200. [rightStack addArrangedSubview:dayBox];
  201. [rightArr addObject:dayBox];
  202.  
  203. [NSLayoutConstraint constraintWithItem:dayBox attribute:NSLayoutAttributeHeight relatedBy:NSLayoutRelationLessThanOrEqual toItem:rightStack attribute:NSLayoutAttributeHeight multiplier:1 constant:0].active = YES;
  204. UILayoutGuide *margin = rightStack.layoutMarginsGuide;
  205. [dayBox.heightAnchor constraintGreaterThanOrEqualToAnchor:margin.heightAnchor].active =YES;
  206.  
  207. [dayBox.leftAnchor constraintEqualToAnchor:rightColumn.leftAnchor].active = YES;
  208. [dayBox.rightAnchor constraintEqualToAnchor:rightColumn.rightAnchor].active = YES;
  209.  
  210.  
  211. if ([rightArr count]>0) {
  212. UIView *tmpbox = rightArr[[rightArr count]-2];
  213. [dayBox.topAnchor constraintEqualToAnchor:tmpbox.bottomAnchor].active=YES;
  214. }
  215.  
  216.  
  217. }
  218. else if(([rightArr count]==[leftArr count])||([rightArr count]>[leftArr count]))
  219. {
  220. [leftStack addArrangedSubview:dayBox];
  221.  
  222. [leftArr addObject:dayBox];
  223.  
  224. [NSLayoutConstraint constraintWithItem:dayBox attribute:NSLayoutAttributeHeight relatedBy:NSLayoutRelationLessThanOrEqual toItem:leftStack attribute:NSLayoutAttributeHeight multiplier:1 constant:0].active = YES;
  225. UILayoutGuide *margin = leftStack.layoutMarginsGuide;
  226. [dayBox.heightAnchor constraintGreaterThanOrEqualToAnchor:margin.heightAnchor].active =YES;
  227.  
  228.  
  229. [dayBox.leftAnchor constraintEqualToAnchor:leftColumn.leftAnchor].active = YES;
  230. [dayBox.rightAnchor constraintEqualToAnchor:leftColumn.rightAnchor].active = YES;
  231.  
  232.  
  233. }
  234. UIStackView *boxStack = [[UIStackView alloc]init];
  235. boxStack.axis = UILayoutConstraintAxisVertical;
  236. boxStack.distribution = UIStackViewDistributionFillEqually;
  237. boxStack.alignment=UIStackViewAlignmentLeading;
  238. boxStack.spacing=2;
  239. boxStack.translatesAutoresizingMaskIntoConstraints = NO;
  240. [dayBox addSubview:boxStack];
  241.  
  242. for (NSString *innerItem in dayStackUIArr) {
  243. UILabel *innerView = [[UILabel alloc]init];
  244. [boxStack addArrangedSubview:innerView];
  245.  
  246. [innerView.leftAnchor constraintEqualToAnchor:dayBox.leftAnchor].active =YES;
  247. [innerView.rightAnchor constraintEqualToAnchor:dayBox.rightAnchor].active =YES;
  248. [innerView.heightAnchor constraintGreaterThanOrEqualToConstant:20].active =YES;
  249. innerView.backgroundColor =[UIColor blueColor];
  250. innerView.text = innerItem;
  251. innerView.font = [UIFont systemFontOfSize:10];
  252.  
  253. }
  254.  
  255.  
  256.  
  257. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement