Changed set_nav_bar_button to accept a system_icon hash key that allows creation of system buttons like add.

This commit is contained in:
Steve Ross
2013-05-16 11:09:45 -07:00
parent c67563b506
commit 543ba8060c
2 changed files with 22 additions and 2 deletions

View File

@@ -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

View File

@@ -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