-
Notifications
You must be signed in to change notification settings - Fork 29
Expand file tree
/
Copy pathORThirdViewController.m
More file actions
88 lines (70 loc) · 3.43 KB
/
ORThirdViewController.m
File metadata and controls
88 lines (70 loc) · 3.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
//
// ORThirdViewController.m
// ARAutoLayoutStackExample
//
// Created by Orta on 10/09/2013.
// Copyright (c) 2013 Orta. All rights reserved.
//
#import "ORThirdViewController.h"
#import "ORColourView.h"
#import <ORStackView/ORTagBasedAutoStackView.h>
// More complex use case: Using tags to ensure order whilst adding in another order
@interface ORThirdViewController()
@property (nonatomic, strong) ORTagBasedAutoStackView *stackView;
@end
@implementation ORThirdViewController
- (UIStatusBarStyle)preferredStatusBarStyle {
return UIStatusBarStyleLightContent;
}
- (void)loadView
{
self.view = [[UIView alloc] init];
}
- (void)viewDidLoad
{
self.stackView = [[ORTagBasedAutoStackView alloc] init];
[self.view addSubview:self.stackView];
if ([self respondsToSelector:@selector(topLayoutGuide)]) {
[self.view addConstraint:[NSLayoutConstraint constraintWithItem:self.stackView attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:self.topLayoutGuide attribute:NSLayoutAttributeBottom multiplier:1.0 constant:0]];
}
[self.view addConstraint:[NSLayoutConstraint constraintWithItem:self.stackView attribute:NSLayoutAttributeWidth relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeWidth multiplier:1.0 constant:0]];
[self.view addConstraint:[NSLayoutConstraint constraintWithItem:self.stackView attribute:NSLayoutAttributeCenterX relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeCenterX multiplier:1.0 constant:0]];
ORColourView *view1 = [[ORColourView alloc] init];
view1.text = @"Tap Me\ntag = 1";
view1.fakeContentSize = (CGSize){ UIViewNoIntrinsicMetric , 70};
view1.tag = 1;
UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(addView)];
[view1 addGestureRecognizer:tapGesture];
ORColourView *view2 = [[ORColourView alloc] init];
view2.text = @"ORTagBasedAutoStackView uses view tags to order your subviews\ntag = 2";
view2.fakeContentSize = (CGSize){ UIViewNoIntrinsicMetric , 70 };
view2.tag = 2;
ORColourView *view4 = [[ORColourView alloc] init];
view4.text = @"tag = 4";
view4.fakeContentSize = (CGSize){ UIViewNoIntrinsicMetric , 50 };
view4.tag = 4;
ORColourView *view5 = [[ORColourView alloc] init];
view5.text = @"tag = 5";
view5.fakeContentSize = (CGSize){ UIViewNoIntrinsicMetric , 60 };
view5.tag = 5;
[self.stackView addSubview:view2 withPrecedingMargin:10.0 sideMargin:40.0];
[self.stackView addSubview:view5 withPrecedingMargin:20.0 sideMargin:20.0];
[self.stackView addSubview:view4 withPrecedingMargin:10.0 sideMargin:20.0];
[self.stackView addSubview:view1 withPrecedingMargin:20.0 sideMargin:30.0];
}
- (void)addView
{
if ([[self.stackView.subviews filteredArrayUsingPredicate:[NSPredicate predicateWithFormat:@"tag = 3"]] count] > 0) return;
ORColourView *view3 = [[ORColourView alloc] init];
view3.text = @"tap to remove me\ntag = 3";
view3.fakeContentSize = (CGSize){ UIViewNoIntrinsicMetric , 50 };
view3.tag = 3;
[self.stackView addSubview:view3 withPrecedingMargin:20.0 sideMargin:70.0];
UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(removeTappedView:)];
[view3 addGestureRecognizer:tapGesture];
}
- (void)removeTappedView:(UITapGestureRecognizer *)gesture
{
[self.stackView removeSubview:gesture.view];
}
@end