-
Notifications
You must be signed in to change notification settings - Fork 29
Expand file tree
/
Copy pathORFirstViewController.m
More file actions
88 lines (67 loc) · 3.54 KB
/
ORFirstViewController.m
File metadata and controls
88 lines (67 loc) · 3.54 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
//
// ORFirstViewController.m
// ARAutoLayoutStackExample
//
// Created by Orta on 15/08/2013.
// Copyright (c) 2013 Orta. All rights reserved.
//
#import "ORFirstViewController.h"
#import "ORColourView.h"
#import <ORStackView/ORStackView.h>
// Simplest use case: Adding views in order
@interface ORFirstViewController ()
@property (nonatomic, strong) ORStackView *stackView;
@end
@implementation ORFirstViewController
- (UIStatusBarStyle)preferredStatusBarStyle {
return UIStatusBarStyleLightContent;
}
- (void)loadView
{
self.view = [[UIView alloc] init];
}
- (void)viewDidLoad
{
self.stackView = [[ORStackView alloc] init];
self.stackView.direction = ORStackViewDirectionHorizontal;
[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]];
} else {
[self.view addConstraint:[NSLayoutConstraint constraintWithItem:self.stackView attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeTop multiplier:1.0 constant:0]];
}
if ([self respondsToSelector:@selector(bottomLayoutGuide)]) {
[self.view addConstraint:[NSLayoutConstraint constraintWithItem:self.stackView attribute:NSLayoutAttributeBottom relatedBy:NSLayoutRelationEqual toItem:self.bottomLayoutGuide attribute:NSLayoutAttributeTop multiplier:1.0 constant:0]];
} else {
[self.view addConstraint:[NSLayoutConstraint constraintWithItem:self.stackView attribute:NSLayoutAttributeBottom relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeBottom multiplier:1.0 constant:0]];
}
[self.view addConstraint:[NSLayoutConstraint constraintWithItem:self.stackView attribute:NSLayoutAttributeLeft relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeLeft multiplier:1.0 constant:0]];
ORColourView *view1 = [[ORColourView alloc] init];
view1.text = @"ORHorizontalStackView - Tap Me";
view1.fakeContentSize = (CGSize){ 40, UIViewNoIntrinsicMetric};
UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(addView)];
[view1 addGestureRecognizer:tapGesture];
ORColourView *view2 = [[ORColourView alloc] init];
view2.text = @"Subtitle";
view2.fakeContentSize = (CGSize){ 30, UIViewNoIntrinsicMetric};
ORColourView *view3 = [[ORColourView alloc] init];
view3.text = @"By default, new subviews are added to the right of ORHorizontalStackView.";
view3.fakeContentSize = (CGSize){ 100, UIViewNoIntrinsicMetric };
[self.stackView addSubview:view1 withPrecedingMargin:20.0 sideMargin:30.0];
[self.stackView addSubview:view2 withPrecedingMargin:10.0 sideMargin:170.0];
[self.stackView addSubview:view3 withPrecedingMargin:30.0 sideMargin:20.0];
}
- (void)addView
{
ORColourView *view = [[ORColourView alloc] init];
view.text = @"Tap to remove";
view.fakeContentSize = (CGSize){ 24, UIViewNoIntrinsicMetric};
[self.stackView addSubview:view withPrecedingMargin:5.0 sideMargin:40.0];
UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(removeTappedView:)];
[view addGestureRecognizer:tapGesture];
}
- (void)removeTappedView:(UITapGestureRecognizer *)gesture
{
[self.stackView removeSubview:gesture.view];
}
@end