diff --git a/ios/Fonts/Rakefile b/ios/Fonts/Rakefile
index 9965176..09a0714 100644
--- a/ios/Fonts/Rakefile
+++ b/ios/Fonts/Rakefile
@@ -1,4 +1,5 @@
$:.unshift("/Library/RubyMotion/lib")
+$:.unshift("~/.rubymotion/rubymotion-templates")
require 'motion/project/template/ios'
Motion::Project::App.setup do |app|
diff --git a/ios/Fonts/app/detail_controller.rb b/ios/Fonts/app/detail_controller.rb
index 0e7d461..7acd9ef 100644
--- a/ios/Fonts/app/detail_controller.rb
+++ b/ios/Fonts/app/detail_controller.rb
@@ -12,6 +12,7 @@ def loadView
def viewDidLoad
navigationItem.title = "Sample Text"
+ navigationItem.rightBarButtonItem = UIBarButtonItem.alloc.initWithBarButtonSystemItem(UIBarButtonSystemItemCompose, target: self, action: :display_font)
end
def viewWillAppear(animated)
@@ -47,4 +48,10 @@ def sample_text
After years of iOS work, RubyMotion seems like a thousand kittens playing the piano while sliding down a double-rainbow.
EOS
end
+
+ def display_font
+ @dynamic_controller ||= DynamicController.alloc.init
+ @dynamic_controller.selected_font(@font_name)
+ self.navigationController.pushViewController(@dynamic_controller, animated:true)
+ end
end
diff --git a/ios/Fonts/app/dynamic_controller.rb b/ios/Fonts/app/dynamic_controller.rb
new file mode 100644
index 0000000..d4540f7
--- /dev/null
+++ b/ios/Fonts/app/dynamic_controller.rb
@@ -0,0 +1,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