This repository has been archived by the owner on Jan 13, 2022. It is now read-only.
/
ButtonTestController.m
165 lines (140 loc) · 6.76 KB
/
ButtonTestController.m
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
#import "ButtonTestController.h"
@interface ButtonTestStyleSheet : TTDefaultStyleSheet
@end
@implementation ButtonTestStyleSheet
- (TTStyle*)blackForwardButton:(UIControlState)state {
TTShape* shape = [TTRoundedRightArrowShape shapeWithRadius:4.5];
UIColor* tintColor = RGBCOLOR(0, 0, 0);
return [TTSTYLESHEET toolbarButtonForState:state shape:shape tintColor:tintColor font:nil];
}
- (TTStyle*)blueToolbarButton:(UIControlState)state {
TTShape* shape = [TTRoundedRectangleShape shapeWithRadius:4.5];
UIColor* tintColor = RGBCOLOR(30, 110, 255);
return [TTSTYLESHEET toolbarButtonForState:state shape:shape tintColor:tintColor font:nil];
}
- (TTStyle*)embossedButton:(UIControlState)state {
if (state == UIControlStateNormal) {
return
[TTShapeStyle styleWithShape:[TTRoundedRectangleShape shapeWithRadius:8] next:
[TTInsetStyle styleWithInset:UIEdgeInsetsMake(0, 0, 1, 0) next:
[TTShadowStyle styleWithColor:RGBACOLOR(255,255,255,0) blur:1 offset:CGSizeMake(0, 1) next:
[TTLinearGradientFillStyle styleWithColor1:RGBCOLOR(255, 255, 255)
color2:RGBCOLOR(216, 221, 231) next:
[TTSolidBorderStyle styleWithColor:RGBCOLOR(161, 167, 178) width:1 next:
[TTBoxStyle styleWithPadding:UIEdgeInsetsMake(10, 12, 9, 12) next:
[TTTextStyle styleWithFont:nil color:TTSTYLEVAR(linkTextColor)
shadowColor:[UIColor colorWithWhite:255 alpha:0.4]
shadowOffset:CGSizeMake(0, -1) next:nil]]]]]]];
} else if (state == UIControlStateHighlighted) {
return
[TTShapeStyle styleWithShape:[TTRoundedRectangleShape shapeWithRadius:8] next:
[TTInsetStyle styleWithInset:UIEdgeInsetsMake(0, 0, 1, 0) next:
[TTShadowStyle styleWithColor:RGBACOLOR(255,255,255,0.9) blur:1 offset:CGSizeMake(0, 1) next:
[TTLinearGradientFillStyle styleWithColor1:RGBCOLOR(225, 225, 225)
color2:RGBCOLOR(196, 201, 221) next:
[TTSolidBorderStyle styleWithColor:RGBCOLOR(161, 167, 178) width:1 next:
[TTBoxStyle styleWithPadding:UIEdgeInsetsMake(10, 12, 9, 12) next:
[TTTextStyle styleWithFont:nil color:[UIColor whiteColor]
shadowColor:[UIColor colorWithWhite:255 alpha:0.4]
shadowOffset:CGSizeMake(0, -1) next:nil]]]]]]];
} else {
return nil;
}
}
- (TTStyle*)dropButton:(UIControlState)state {
if (state == UIControlStateNormal) {
return
[TTShapeStyle styleWithShape:[TTRoundedRectangleShape shapeWithRadius:8] next:
[TTShadowStyle styleWithColor:RGBACOLOR(0,0,0,0.7) blur:3 offset:CGSizeMake(2, 2) next:
[TTInsetStyle styleWithInset:UIEdgeInsetsMake(0.25, 0.25, 0.25, 0.25) next:
[TTSolidFillStyle styleWithColor:[UIColor whiteColor] next:
[TTInsetStyle styleWithInset:UIEdgeInsetsMake(-0.25, -0.25, -0.25, -0.25) next:
[TTSolidBorderStyle styleWithColor:RGBCOLOR(161, 167, 178) width:1 next:
[TTInsetStyle styleWithInset:UIEdgeInsetsMake(2, 0, 0, 0) next:
[TTBoxStyle styleWithPadding:UIEdgeInsetsMake(11, 10, 9, 10) next:
[TTTextStyle styleWithFont:nil color:TTSTYLEVAR(linkTextColor)
shadowColor:[UIColor colorWithWhite:255 alpha:0.4]
shadowOffset:CGSizeMake(0, -1) next:nil]]]]]]]]];
} else if (state == UIControlStateHighlighted) {
return
[TTInsetStyle styleWithInset:UIEdgeInsetsMake(3, 3, 0, 0) next:
[TTShapeStyle styleWithShape:[TTRoundedRectangleShape shapeWithRadius:8] next:
[TTSolidFillStyle styleWithColor:[UIColor whiteColor] next:
[TTSolidBorderStyle styleWithColor:RGBCOLOR(161, 167, 178) width:1 next:
[TTInsetStyle styleWithInset:UIEdgeInsetsMake(2, 0, 0, 0) next:
[TTBoxStyle styleWithPadding:UIEdgeInsetsMake(11, 10, 9, 10) next:
[TTTextStyle styleWithFont:nil color:TTSTYLEVAR(linkTextColor)
shadowColor:[UIColor colorWithWhite:255 alpha:0.4]
shadowOffset:CGSizeMake(0, -1) next:nil]]]]]]];
} else {
return nil;
}
}
@end
@implementation ButtonTestController
///////////////////////////////////////////////////////////////////////////////////////////////////
// private
- (void)layout {
TTFlowLayout* flowLayout = [[[TTFlowLayout alloc] init] autorelease];
flowLayout.padding = 20;
flowLayout.spacing = 20;
CGSize size = [flowLayout layoutSubviews:self.view.subviews forView:self.view];
UIScrollView* scrollView = (UIScrollView*)self.view;
scrollView.contentSize = CGSizeMake(scrollView.width, size.height);
}
- (void)increaseFont {
_fontSize += 4;
for (UIView* view in self.view.subviews) {
if ([view isKindOfClass:[TTButton class]]) {
TTButton* button = (TTButton*)view;
button.font = [UIFont boldSystemFontOfSize:_fontSize];
[button sizeToFit];
}
}
[self layout];
}
///////////////////////////////////////////////////////////////////////////////////////////////////
// NSObject
- (id)init {
if (self = [super init]) {
_fontSize = 12;
[TTStyleSheet setGlobalStyleSheet:[[[ButtonTestStyleSheet alloc] init] autorelease]];
}
return self;
}
- (void)dealloc {
[TTStyleSheet setGlobalStyleSheet:nil];
[super dealloc];
}
///////////////////////////////////////////////////////////////////////////////////////////////////
// UIViewController
- (void)loadView {
self.navigationItem.rightBarButtonItem
= [[[UIBarButtonItem alloc] initWithTitle:@"Increase Font" style:UIBarButtonItemStyleBordered
target:self action:@selector(increaseFont)] autorelease];
UIScrollView* scrollView = [[[UIScrollView alloc] initWithFrame:TTNavigationFrame()] autorelease];
scrollView.autoresizesSubviews = YES;
scrollView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
scrollView.backgroundColor = RGBCOLOR(216, 221, 231);
//scrollView.backgroundColor = RGBCOLOR(119, 140, 168);
scrollView.canCancelContentTouches = NO;
scrollView.delaysContentTouches = NO;
self.view = scrollView;
NSArray* buttons = [NSArray arrayWithObjects:
[TTButton buttonWithStyle:@"toolbarButton:" title:@"Toolbar Button"],
[TTButton buttonWithStyle:@"toolbarRoundButton:" title:@"Round Button"],
[TTButton buttonWithStyle:@"toolbarBackButton:" title:@"Back Button"],
[TTButton buttonWithStyle:@"toolbarForwardButton:" title:@"Forward Button"],
[TTButton buttonWithStyle:@"blackForwardButton:" title:@"Black Button"],
[TTButton buttonWithStyle:@"blueToolbarButton:" title:@"Blue Button"],
[TTButton buttonWithStyle:@"embossedButton:" title:@"Embossed Button"],
[TTButton buttonWithStyle:@"dropButton:" title:@"Shadow Button"],
nil];
for (TTButton* button in buttons) {
button.font = [UIFont boldSystemFontOfSize:_fontSize];
[button sizeToFit];
[scrollView addSubview:button];
}
[self layout];
}
@end