From 543ba8060ca3e867b35453168ab2c98b5472b41b Mon Sep 17 00:00:00 2001 From: Steve Ross Date: Thu, 16 May 2013 11:09:45 -0700 Subject: [PATCH] Changed set_nav_bar_button to accept a system_icon hash key that allows creation of system buttons like add. --- lib/ProMotion/screens/_screen_module.rb | 10 ++++++++-- spec/screen_spec.rb | 14 ++++++++++++++ 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/lib/ProMotion/screens/_screen_module.rb b/lib/ProMotion/screens/_screen_module.rb index 7de8e43..9eadea6 100644 --- a/lib/ProMotion/screens/_screen_module.rb +++ b/lib/ProMotion/screens/_screen_module.rb @@ -71,12 +71,18 @@ module ProMotion set_nav_bar_button :left, args end + # If you call set_nav_bar_button with a nil title and system_icon: UIBarButtonSystemItemAdd (or any other + # system icon), the button is initialized with a barButtonSystemItem instead of a title. 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[:system_icon] + button = UIBarButtonItem.alloc.initWithBarButtonSystemItem(args[:system_icon], 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 diff --git a/spec/screen_spec.rb b/spec/screen_spec.rb index 4ca5932..da80eac 100644 --- a/spec/screen_spec.rb +++ b/spec/screen_spec.rb @@ -108,4 +108,18 @@ describe "screen properties" do end + describe "bar button behavior" do + before do + @screen.set_nav_bar_right_button nil, action: :add_something, system_icon: UIBarButtonSystemItemAdd + end + + it "has a right bar button item of the correct type" do + @screen.navigationItem.rightBarButtonItem.should.be.instance_of UIBarButtonItem + end + + it "is an add button" do + @screen.navigationItem.rightBarButtonItem.action.should == :add_something + end + end + end