forked from soffes/cheddar-ios
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CDISettingsFontPickerViewController.m
93 lines (70 loc) · 2.62 KB
/
CDISettingsFontPickerViewController.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
//
// CDISettingsFontPickerViewController.m
// Cheddar for iOS
//
// Created by Sam Soffes on 7/29/12.
// Copyright (c) 2012 Nothing Magical. All rights reserved.
//
#import "CDISettingsFontPickerViewController.h"
#import "CDISettingsViewController.h"
#import "UIFont+CheddariOSAdditions.h"
#import <SSToolkit/NSString+SSToolkitAdditions.h>
NSString *const kCDIFontDefaultsKey = @"CDIFontDefaults";
NSString *const kCDIFontGothamKey = @"Gotham";
NSString *const kCDIFontHelveticaNeueKey = @"HelveticaNeue";
NSString *const kCDIFontHoeflerKey = @"Hoefler";
NSString *const kCDIFontAvenirKey = @"Avenir";
@implementation CDISettingsFontPickerViewController
#pragma mark - Class Methods
+ (NSString *)defaultsKey {
return kCDIFontDefaultsKey;
}
+ (NSDictionary *)valueMap {
static NSDictionary *map = nil;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
if ([self supportsAvenir]) {
map = [[NSDictionary alloc] initWithObjectsAndKeys:
@"Gotham", kCDIFontGothamKey,
@"Helvetica Neue", kCDIFontHelveticaNeueKey,
@"Hoefler", kCDIFontHoeflerKey,
@"Avenir", kCDIFontAvenirKey,
nil];
} else {
map = [[NSDictionary alloc] initWithObjectsAndKeys:
@"Gotham", kCDIFontGothamKey,
@"Helvetica Neue", kCDIFontHelveticaNeueKey,
@"Hoefler", kCDIFontHoeflerKey,
nil];
}
});
return map;
}
- (NSArray *)keys {
if ([[self class] supportsAvenir]) {
return [[NSArray alloc] initWithObjects:kCDIFontGothamKey, kCDIFontHelveticaNeueKey, kCDIFontHoeflerKey, kCDIFontAvenirKey, nil];
}
return [[NSArray alloc] initWithObjects:kCDIFontGothamKey, kCDIFontHelveticaNeueKey, kCDIFontHoeflerKey, nil];
}
+ (BOOL)supportsAvenir {
NSComparisonResult result = [[[UIDevice currentDevice] systemVersion] compareToVersionString:@"6.0"];
return result == NSOrderedDescending || result == NSOrderedSame;
}
#pragma mark - UIViewController
- (void)viewDidLoad {
[super viewDidLoad];
self.title = @"Font";
}
#pragma mark - UITableViewDataSource
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = [super tableView:tableView cellForRowAtIndexPath:indexPath];
NSString *key = [[self keys] objectAtIndex:indexPath.row];
cell.textLabel.font = [UIFont cheddarFontOfSize:18.0f fontKey:key];
return cell;
}
#pragma mark - UITableViewDelegate
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
[super tableView:tableView didSelectRowAtIndexPath:indexPath];
[[NSNotificationCenter defaultCenter] postNotificationName:kCDIFontDidChangeNotificationName object:nil];
}
@end