Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathSSViewController.m
More file actions
Latest commit
148 lines (118 loc) · 6.41 KB
/
Copy pathSSViewController.m
File metadata and controls
148 lines (118 loc) · 6.41 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
//
// SSViewController.m
// SSLabelExample
//
// Created by Jonathan Hersh on 10/4/13.
// Copyright (c) 2013 Splinesoft. All rights reserved.
//
#import"SSViewController.h"
#import<SSDynamicText.h>
staticNSString * constkLabelText = @"This label, text field, and text view all support custom fonts and respond to changes in preferred text size.\n\nSwitch to Settings.app, change your preferred text size, then switch back here.";
@interfaceSSViewController ()
@property (nonatomic, strong) SSDynamicLabel *label;
@property (nonatomic, strong) SSDynamicButton *button;
@property (nonatomic, strong) SSDynamicTextField *textField;
@property (nonatomic, strong) SSDynamicTextView *textView;
@property (nonatomic, assign) BOOL isAttributedTextCurrentlyDisplayed;
@end
@implementationSSViewController
- (void)changeTexts:(UIButton *)sender {
if (self.isAttributedTextCurrentlyDisplayed) {
[selfdisplayNormalTexts];
} else {
[selfdisplayAttributedTexts];
}
self.isAttributedTextCurrentlyDisplayed = !self.isAttributedTextCurrentlyDisplayed;
}
- (void)displayNormalTexts {
self.label.dynamicAttributedText = nil;
self.textField.dynamicAttributedText = nil;
self.textView.dynamicAttributedText = nil;
[self.button setAttributedTitle:nilforState:UIControlStateNormal];
self.label.text = kLabelText;
self.textView.text = @"Text View";
[self.button setTitle:@"Change to attributed"forState:UIControlStateNormal];
}
- (void)setLabelAttributedTextWithFirstAttributes:(NSDictionary *)attributessecondAttributes:(NSDictionary *)secondAttributes {
NSMutableAttributedString *labelText = [[NSMutableAttributedStringalloc] initWithString:kLabelText
attributes:attributes];
[labelText addAttributes:secondAttributes range:[kLabelTextrangeOfString:@"change your preferred text size"]];
self.label.dynamicAttributedText = labelText;
}
- (void)setTextFieldAttributedTextWithFirstAttributes:(NSDictionary *)attributessecondAttributes:(NSDictionary *)secondAttributes {
NSString *textFieldString = @"TextField support";
NSMutableAttributedString *textFieldText = [[NSMutableAttributedStringalloc] initWithString:textFieldString
attributes:attributes];
[textFieldText addAttributes:secondAttributes range:[textFieldString rangeOfString:@"TextField"]];
self.textField.dynamicAttributedText = textFieldText;
}
- (void)setTextViewAttributedTextWithFirstAttributes:(NSDictionary *)attributessecondAttributes:(NSDictionary *)secondAttributes {
NSString *textViewString = @"I hope this also works for TextView";
NSMutableAttributedString *textViewText = [[NSMutableAttributedStringalloc] initWithString:textViewString
attributes:attributes];
[textViewText addAttributes:secondAttributes range:[textViewString rangeOfString:@"works for TextView"]];
self.textView.dynamicAttributedText = textViewText;
}
- (void)setButtonAttributedTextWithFirstAttributes:(NSDictionary *)attributessecondAttributes:(NSDictionary *)secondAttributes {
NSString *buttonString = @"Change to normal";
NSMutableAttributedString *buttonText = [[NSMutableAttributedStringalloc] initWithString:buttonString
attributes:attributes];
[buttonText addAttributes:secondAttributes range:[buttonString rangeOfString:@"normal"]];
[self.button setAttributedTitle:buttonText forState:UIControlStateNormal];
}
- (void)displayAttributedTexts {
self.label.text = nil;
self.textField.text = nil;
self.textView.text = nil;
NSDictionary *attributes =
@{NSForegroundColorAttributeName: [UIColor blackColor], NSFontAttributeName: [UIFont systemFontOfSize:16.0f]};
NSDictionary *secondAttributes =
@{NSForegroundColorAttributeName: [UIColor blueColor], NSFontAttributeName: [UIFont fontWithName:@"Courier"size:25.0f]};
[selfsetLabelAttributedTextWithFirstAttributes:attributes secondAttributes:secondAttributes];
[selfsetTextFieldAttributedTextWithFirstAttributes:attributes secondAttributes:secondAttributes];
[selfsetTextViewAttributedTextWithFirstAttributes:attributes secondAttributes:secondAttributes];
[selfsetButtonAttributedTextWithFirstAttributes:attributes secondAttributes:secondAttributes];
}
- (void)viewDidLoad {
[superviewDidLoad];
self.view.backgroundColor = [UIColor whiteColor];
self.label = [SSDynamicLabel labelWithFont:@"Courier"baseSize:16.0f];
self.label.textColor = [UIColor darkGrayColor];
self.label.numberOfLines = 0;
self.label.textAlignment = NSTextAlignmentCenter;
[self.label setFrame:(CGRect){
{10, 25},
{CGRectGetWidth(self.view.frame) - 20, 220}
}];
[self.view addSubview:self.label];
self.button = [SSDynamicButton buttonWithFont:@"Courier"baseSize:16.0f];
[self.button setTitleColor:[UIColor blueColor] forState:UIControlStateNormal];
self.button.backgroundColor = [UIColor lightGrayColor];
[self.button setFrame:(CGRect){
{10, CGRectGetMaxY(self.label.frame) + 10},
{CGRectGetWidth(self.view.frame) - 20, 44}
}];
[self.button addTarget:selfaction:@selector(changeTexts:) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:self.button];
self.textField = [SSDynamicTextField textFieldWithFont:@"Courier"
baseSize:15.0f];
self.textField.textColor = [UIColor darkGrayColor];
self.textField.backgroundColor = [UIColor lightGrayColor];
self.textField.placeholder = @"Text Field";
[self.textField setFrame:(CGRect){
{10, CGRectGetMaxY(self.button.frame) + 10},
{CGRectGetWidth(self.view.frame) - 20, 32}
}];
[self.view addSubview:self.textField];
self.textView = [SSDynamicTextView textViewWithFont:@"Courier"
baseSize:15.0f];
self.textView.textColor = [UIColor redColor];
self.textView.backgroundColor = [UIColor lightGrayColor];
[self.textView setFrame:(CGRect){
{10, CGRectGetMaxY(self.textField.frame) + 10},
{CGRectGetWidth(self.view.frame) - 20, 100}
}];
[self.view addSubview:self.textView];
[selfdisplayNormalTexts];
}
@end