From fd5620eae36c0ce5b3c9ca5d001e326d59775fcd Mon Sep 17 00:00:00 2001 From: Mark Rickert Date: Wed, 15 May 2013 21:21:09 -0400 Subject: [PATCH 1/7] Allow user to specify a UIImage as the title for a nav bar button item. --- lib/ProMotion/screens/_screen_module.rb | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/ProMotion/screens/_screen_module.rb b/lib/ProMotion/screens/_screen_module.rb index 7de8e43..05ccef2 100644 --- a/lib/ProMotion/screens/_screen_module.rb +++ b/lib/ProMotion/screens/_screen_module.rb @@ -70,13 +70,17 @@ module ProMotion args[:title] = title set_nav_bar_button :left, args end - + def set_nav_bar_button(side, args={}) args[:style] ||= UIBarButtonItemStyleBordered args[:target] ||= self args[:action] ||= nil - button = UIBarButtonItem.alloc.initWithTitle(args[:title], style: args[:style], target: args[:target], action: args[:action]) + if args[:title].is_a?(UIImage) + button = UIBarButtonItem.alloc.initWithImage(args[:title], style: args[:style], target: args[:target], action: args[:action]) + else + button = UIBarButtonItem.alloc.initWithTitle(args[:title], style: args[:style], target: args[:target], action: args[:action]) + end self.navigationItem.leftBarButtonItem = button if side == :left self.navigationItem.rightBarButtonItem = button if side == :right From 5abd3481beff33011f5c733ee2aad6d91a97b1c1 Mon Sep 17 00:00:00 2001 From: Mark Rickert Date: Thu, 16 May 2013 09:17:59 -0400 Subject: [PATCH 2/7] Update readme to note that UIImages can be sent to create UIBarButtons --- README.md | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index c36f34d..8d81170 100644 --- a/README.md +++ b/README.md @@ -244,6 +244,8 @@ set_nav_bar_right_button "Save", action: :save_something, type: UIBarButtonItemS set_nav_bar_left_button "Cancel", action: :return_to_some_other_screen, type: UIBarButtonItemStylePlain ``` +If you pass an instance of a `UIImage`, the `UIBarButton` will automatically display with that image instead of text. *Don't forget retina and landscape versions of your image!* + ## Opening and closing screens If the user taps something and you want to open a new screen, it's easy. Just use `open` and pass in the screen class @@ -284,7 +286,6 @@ class ProfileScreen < ProMotion::Screen self.user # => some_user instance end end - ``` Closing a screen is as easy as can be. @@ -564,12 +565,14 @@ end set_nav_bar_left_button(title, args = {}) Set a left nav bar button.
+ `title` can be a `String` or a `UIImage`. set_nav_bar_right_button(title, args = {}) Set a right nav bar button.
+ `title` can be a `String` or a `UIImage`. From 2e8697e9b55a85e2940cf6426fa7a4c4c4c4d69a Mon Sep 17 00:00:00 2001 From: Mark Rickert Date: Thu, 16 May 2013 09:34:45 -0400 Subject: [PATCH 3/7] Update test app rakefile for RM2.0 syntax --- Rakefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Rakefile b/Rakefile index 37bb157..34e30b9 100644 --- a/Rakefile +++ b/Rakefile @@ -1,5 +1,5 @@ $:.unshift("/Library/RubyMotion/lib") -require 'motion/project' +require 'motion/project/template/ios' require 'bundler/gem_tasks' Bundler.setup Bundler.require From 8acdeaf7cd3515d4f2ce15c37627c33087541c4d Mon Sep 17 00:00:00 2001 From: Mark Rickert Date: Thu, 16 May 2013 09:35:08 -0400 Subject: [PATCH 4/7] Add tests for creating a UIBarButton with a UIImage. --- resources/list.png | Bin 0 -> 104 bytes spec/helpers/home_screen.rb | 4 ++-- spec/screen_helpers_spec.rb | 15 ++++++++++----- 3 files changed, 12 insertions(+), 7 deletions(-) create mode 100755 resources/list.png diff --git a/resources/list.png b/resources/list.png new file mode 100755 index 0000000000000000000000000000000000000000..263cffd387c6486ab1a0d8969b304754bc3277eb GIT binary patch literal 104 zcmeAS@N?(olHy`uVBq!ia0vp^;y^6S!3HF&cTd{}r1U*q978H@y}f8C$iTpH_<)xa z(?4HEWwuRA%OiK! Date: Thu, 16 May 2013 09:37:51 -0400 Subject: [PATCH 5/7] One more test to make sure it's the RIGHT image ;) --- spec/screen_helpers_spec.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/spec/screen_helpers_spec.rb b/spec/screen_helpers_spec.rb index cff3c71..72bd300 100644 --- a/spec/screen_helpers_spec.rb +++ b/spec/screen_helpers_spec.rb @@ -55,8 +55,10 @@ describe "screen helpers" do end it "should add an image right nav bar button" do - @screen.set_nav_bar_right_button UIImage.imageNamed("list.png"), action: :return_to_some_other_screen, type: UIBarButtonItemStylePlain + image = UIImage.imageNamed("list.png") + @screen.set_nav_bar_right_button image, action: :return_to_some_other_screen, type: UIBarButtonItemStylePlain @screen.navigationItem.rightBarButtonItem.image.class.should == UIImage + @screen.navigationItem.rightBarButtonItem.image.should == image end end From 4117fe9e92b1007fd72c85cfd948012a9d176626 Mon Sep 17 00:00:00 2001 From: Mark Rickert Date: Thu, 16 May 2013 12:22:10 -0400 Subject: [PATCH 6/7] Added tests for the left bar button item. --- spec/screen_helpers_spec.rb | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/spec/screen_helpers_spec.rb b/spec/screen_helpers_spec.rb index 72bd300..ae6c14f 100644 --- a/spec/screen_helpers_spec.rb +++ b/spec/screen_helpers_spec.rb @@ -61,6 +61,13 @@ describe "screen helpers" do @screen.navigationItem.rightBarButtonItem.image.should == image end + it "should add an image left nav bar button" do + image = UIImage.imageNamed("list.png") + @screen.set_nav_bar_left_button image, action: :return_to_some_other_screen, type: UIBarButtonItemStylePlain + @screen.navigationItem.leftBarButtonItem.image.class.should == UIImage + @screen.navigationItem.leftBarButtonItem.image.should == image + end + end describe "screen navigation" do From 75e187381530d940546582ce0ae71e4fa0418067 Mon Sep 17 00:00:00 2001 From: Jamon Holmgren Date: Thu, 16 May 2013 10:57:23 -0700 Subject: [PATCH 7/7] Switched demo app link --- README.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index ed0df5e..f60246b 100644 --- a/README.md +++ b/README.md @@ -50,7 +50,9 @@ http://www.clearsightstudio.com/insights/tutorial-make-youtube-video-app-rubymot ## Sample Apps -[https://github.com/jamonholmgren/promotion-tutorial](https://github.com/jamonholmgren/promotion-tutorial) +This is pretty bare-bones, but we'll be building it out as we go along. + +[https://github.com/jamonholmgren/promotion-demo](https://github.com/jamonholmgren/promotion-demo) ## Apps Built With ProMotion