mirror of
https://github.com/zhigang1992/ProMotion.git
synced 2026-06-01 19:49:13 +08:00
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:
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user