forked from Grouper/FlatUIKit
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathViewController.m
More file actions
236 lines (198 loc) · 12.1 KB
/
ViewController.m
File metadata and controls
236 lines (198 loc) · 12.1 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
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
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
//
// ViewController.m
// FlatUI
//
// Created by Jack Flintermann on 5/3/13.
// Copyright (c) 2013 Jack Flintermann. All rights reserved.
//
#import "ViewController.h"
#import "TableViewController.h"
#import "UIColor+FlatUI.h"
#import "UISlider+FlatUI.h"
#import "UIStepper+FlatUI.h"
#import "UITabBar+FlatUI.h"
#import "UINavigationBar+FlatUI.h"
#import "FUIButton.h"
#import "FUISwitch.h"
#import "UIFont+FlatUI.h"
#import "FUIAlertView.h"
#import "UIBarButtonItem+FlatUI.h"
#import "UIProgressView+FlatUI.h"
#import "FUISegmentedControl.h"
#import "UIPopoverController+FlatUI.h"
#import "NSString+Icons.h"
#import "IconViewController.h"
#define SYSTEM_VERSION_EQUAL_TO(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == NSOrderedSame)
#define SYSTEM_VERSION_GREATER_THAN(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == NSOrderedDescending)
#define SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] != NSOrderedAscending)
#define SYSTEM_VERSION_LESS_THAN(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == NSOrderedAscending)
#define SYSTEM_VERSION_LESS_THAN_OR_EQUAL_TO(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] != NSOrderedDescending)
@interface ViewController () {
UIPopoverController *_popoverController;
}
@property (weak, nonatomic) IBOutlet FUIButton *alertViewButton;
@property (weak, nonatomic) IBOutlet FUIButton *popoverButton;
@property (weak, nonatomic) IBOutlet UISlider *slider;
@property (weak, nonatomic) IBOutlet UIStepper *stepper;
@property (weak, nonatomic) IBOutlet FUISwitch *flatSwitch;
@property (strong, nonatomic) IBOutletCollection(UILabel) NSArray *labels;
@property (weak, nonatomic) IBOutlet UIProgressView *flatProgress;
@property (weak, nonatomic) IBOutlet FUISegmentedControl *flatSegmentedControl;
@property (weak, nonatomic) IBOutlet FUIButton *iconsButton;
@end
@implementation ViewController
- (void)viewDidLoad
{
[super viewDidLoad];
if ([UIDevice currentDevice].systemVersion.floatValue >= 7) {
self.edgesForExtendedLayout = UIRectEdgeNone;
}
self.title = @"Flat UI";
self.view.backgroundColor = [UIColor cloudsColor];
NSDictionary *attrs = @{NSForegroundColorAttributeName: [UIColor whiteColor]};
[[UIBarItem appearance] setTitleTextAttributes:attrs
forState:UIControlStateNormal];
[UIBarButtonItem configureFlatButtonsWithColor:[UIColor peterRiverColor]
highlightedColor:[UIColor belizeHoleColor]
cornerRadius:3
whenContainedIn:[UINavigationBar class], nil];
self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"Plain Table"
style:UIBarButtonItemStylePlain
target:self
action:@selector(showPlainTableView:)];
[self.navigationItem.rightBarButtonItem removeTitleShadow];
self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"Grouped Table"
style:UIBarButtonItemStylePlain
target:self
action:@selector(showTableView:)];
[self.navigationItem.leftBarButtonItem removeTitleShadow];
[self.navigationItem.leftBarButtonItem configureFlatButtonWithColor:[UIColor alizarinColor]
highlightedColor:[UIColor pomegranateColor]
cornerRadius:3];
self.alertViewButton.buttonColor = [UIColor turquoiseColor];
self.alertViewButton.shadowColor = [UIColor greenSeaColor];
self.alertViewButton.shadowHeight = 3.0f;
self.alertViewButton.cornerRadius = 6.0f;
self.alertViewButton.titleLabel.font = [UIFont boldFlatFontOfSize:16];
[self.alertViewButton setTitleColor:[UIColor cloudsColor] forState:UIControlStateNormal];
[self.alertViewButton setTitleColor:[UIColor cloudsColor] forState:UIControlStateHighlighted];
self.iconsButton.titleLabel.font = [UIFont iconFontWithSize:16];
self.iconsButton.buttonColor = [UIColor turquoiseColor];
self.iconsButton.shadowColor = [UIColor greenSeaColor];
self.iconsButton.shadowHeight = 3.0f;
self.iconsButton.cornerRadius = 6.0f;
[self.iconsButton setTitle:[NSString stringWithFormat:@"%@ Icons", [NSString iconStringForEnum:FUIListBulleted]] forState:UIControlStateNormal];
[self.iconsButton setTitleColor:[UIColor cloudsColor] forState:UIControlStateNormal];
[self.iconsButton addTarget:self action:@selector(iconsButtonPressed:) forControlEvents:UIControlEventTouchUpInside];
[self.slider configureFlatSliderWithTrackColor:[UIColor silverColor]
progressColor:[UIColor alizarinColor]
thumbColor:[UIColor pomegranateColor]];
[self.stepper configureFlatStepperWithColor:[UIColor wisteriaColor]
highlightedColor:[UIColor amethystColor]
disabledColor:[UIColor silverColor]
iconColor:[UIColor cloudsColor]];
if (SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"7.0")) {
self.navigationController.navigationBar.titleTextAttributes = @{NSFontAttributeName:[UIFont boldFlatFontOfSize:18],
NSForegroundColorAttributeName: [UIColor whiteColor]};
} else {
// Pre-iOS7 methods
self.navigationController.navigationBar.titleTextAttributes = @{UITextAttributeFont: [UIFont boldFlatFontOfSize:18],
UITextAttributeTextColor: [UIColor whiteColor]};
}
[self.navigationController.navigationBar configureFlatNavigationBarWithColor:[UIColor midnightBlueColor]];
self.flatSwitch.onColor = [UIColor turquoiseColor];
self.flatSwitch.offColor = [UIColor cloudsColor];
self.flatSwitch.onBackgroundColor = [UIColor midnightBlueColor];
self.flatSwitch.offBackgroundColor = [UIColor silverColor];
self.flatSwitch.offLabel.font = [UIFont boldFlatFontOfSize:14];
self.flatSwitch.onLabel.font = [UIFont boldFlatFontOfSize:14];
[self.labels enumerateObjectsUsingBlock:^(UILabel *label, NSUInteger idx, BOOL *stop) {
label.font = [UIFont flatFontOfSize:16];
label.textColor = [UIColor midnightBlueColor];
}];
[self.flatProgress configureFlatProgressViewWithTrackColor:[UIColor silverColor] progressColor:[UIColor wisteriaColor]];
self.flatSegmentedControl.selectedFont = [UIFont boldFlatFontOfSize:16];
self.flatSegmentedControl.selectedFontColor = [UIColor cloudsColor];
self.flatSegmentedControl.deselectedFont = [UIFont flatFontOfSize:16];
self.flatSegmentedControl.deselectedFontColor = [UIColor cloudsColor];
self.flatSegmentedControl.selectedColor = [UIColor pumpkinColor];
self.flatSegmentedControl.deselectedColor = [UIColor tangerineColor];
self.flatSegmentedControl.disabledColor = [UIColor silverColor];
self.flatSegmentedControl.dividerColor = [UIColor silverColor];
self.flatSegmentedControl.cornerRadius = 5.0;
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad) {
self.popoverButton.buttonColor = [UIColor carrotColor];
self.popoverButton.shadowColor = [UIColor alizarinColor];
self.popoverButton.shadowHeight = 3.0f;
self.popoverButton.cornerRadius = 6.0f;
self.popoverButton.titleLabel.font = [UIFont boldFlatFontOfSize:16];
[self.popoverButton setTitleColor:[UIColor cloudsColor] forState:UIControlStateNormal];
[self.popoverButton setTitleColor:[UIColor cloudsColor] forState:UIControlStateHighlighted];
}
}
- (IBAction)showAlertView:(id)sender {
FUIAlertView *alertView = [[FUIAlertView alloc] initWithTitle:@"Hello" message:@"This is an alert view" delegate:nil cancelButtonTitle:@"Dismiss" otherButtonTitles:@"Do Something", nil];
alertView.alertViewStyle = FUIAlertViewStylePlainTextInput;
[@[[alertView textFieldAtIndex:0], [alertView textFieldAtIndex:1]] enumerateObjectsUsingBlock:^(FUITextField *textField, NSUInteger idx, BOOL *stop) {
[textField setTextFieldColor:[UIColor cloudsColor]];
[textField setBorderColor:[UIColor asbestosColor]];
[textField setCornerRadius:4];
[textField setFont:[UIFont flatFontOfSize:14]];
[textField setTextColor:[UIColor midnightBlueColor]];
}];
[[alertView textFieldAtIndex:0] setPlaceholder:@"Text here!"];
alertView.delegate = self;
alertView.titleLabel.textColor = [UIColor cloudsColor];
alertView.titleLabel.font = [UIFont boldFlatFontOfSize:16];
alertView.messageLabel.textColor = [UIColor cloudsColor];
alertView.messageLabel.font = [UIFont flatFontOfSize:14];
alertView.backgroundOverlay.backgroundColor = [[UIColor cloudsColor] colorWithAlphaComponent:0.8];
alertView.alertContainer.backgroundColor = [UIColor midnightBlueColor];
alertView.defaultButtonColor = [UIColor cloudsColor];
alertView.defaultButtonShadowColor = [UIColor asbestosColor];
alertView.defaultButtonFont = [UIFont boldFlatFontOfSize:16];
alertView.defaultButtonTitleColor = [UIColor asbestosColor];
[alertView show];
}
- (IBAction)showPopover:(id)sender {
UIButton *button = (UIButton *)sender;
UIViewController *vc = [[UIViewController alloc] init];
vc.view.backgroundColor = [UIColor whiteColor];
vc.title = @"FUIPopoverController";
if (SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"7.0")) {
vc.preferredContentSize = CGSizeMake(320, 480);
self.navigationController.navigationBar.titleTextAttributes = @{NSFontAttributeName:[UIFont boldFlatFontOfSize:18],
NSForegroundColorAttributeName: [UIColor whiteColor]};
} else {
// Pre-iOS7 methods
vc.contentSizeForViewInPopover = CGSizeMake(320, 480);
vc.navigationController.navigationBar.titleTextAttributes = @{UITextAttributeFont: [UIFont boldFlatFontOfSize:18],
UITextAttributeTextColor: [UIColor whiteColor]};
}
UINavigationController *nc = [[UINavigationController alloc] initWithRootViewController:vc];
_popoverController = [[UIPopoverController alloc] initWithContentViewController:nc];
[_popoverController configureFlatPopoverWithBackgroundColor:[UIColor turquoiseColor] cornerRadius:9.0];
_popoverController.delegate = self;
[_popoverController presentPopoverFromRect:button.frame inView:self.view permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
}
- (void)showTableView:(id)sender {
TableViewController* tableViewController = [[TableViewController alloc] initWithStyle:UITableViewStyleGrouped];
[self.navigationController pushViewController:tableViewController animated:YES];
}
- (void)showPlainTableView:(id)sender {
TableViewController* tableViewController = [[TableViewController alloc] initWithStyle:UITableViewStylePlain];
[self.navigationController pushViewController:tableViewController animated:YES];
}
-(void)iconsButtonPressed:(UIButton*)button {
IconViewController *iconViewController = [[IconViewController alloc]init];
[self.navigationController pushViewController:iconViewController animated:YES];
}
#pragma mark - UIPopoverControllerDelegate Methods
- (BOOL)popoverControllerShouldDismissPopover:(UIPopoverController *)popoverController
{
return YES;
}
- (void) popoverControllerDidDismissPopover:(UIPopoverController *)popoverController {
_popoverController = nil;
}
@end