-
Notifications
You must be signed in to change notification settings - Fork 333
Expand file tree
/
Copy pathdynamic_controller.rb
More file actions
53 lines (44 loc) · 1.48 KB
/
dynamic_controller.rb
File metadata and controls
53 lines (44 loc) · 1.48 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
class DynamicController < UIViewController
TEXT_STYLES = [
UIFontTextStyleBody,
UIFontTextStyleCallout,
UIFontTextStyleCaption1,
UIFontTextStyleCaption2,
UIFontTextStyleFootnote,
UIFontTextStyleHeadline,
UIFontTextStyleSubheadline,
UIFontTextStyleLargeTitle,
UIFontTextStyleTitle1,
UIFontTextStyleTitle2,
UIFontTextStyleTitle3,
]
def loadView
self.view = UIScrollView.alloc.initWithFrame(UIScreen.mainScreen.applicationFrame)
view.backgroundColor = UIColor.whiteColor
@labels = TEXT_STYLES.map do |style|
label = UILabel.alloc.init
view.addSubview(label)
{:label => label, :style => style, size: UIFont.preferredFontForTextStyle(style).pointSize}
end
end
def viewDidLoad
navigationItem.title = "Dynamic Text - #{@font_name}"
end
def viewWillAppear(_)
top = 100
@labels.each do |label_style|
metrics = UIFontMetrics.metricsForTextStyle(label_style[:style])
label_style[:label].font = metrics.scaledFontForFont(UIFont.fontWithName(@font_name, size: label_style[:size]))
label_style[:label].text = label_style[:style]
label_style[:label].adjustsFontForContentSizeCategory = true
label_style[:label].frame = [
[10, top], [
view.frame.size.width - 20, label_style[:label].font.pointSize + 5]
]
top += label_style[:label].font.pointSize + 20
end
end
def selected_font(font_name)
@font_name = font_name
end
end