mirror of
https://github.com/zhigang1992/ProMotion.git
synced 2026-06-02 06:49:45 +08:00
Merge pull request #67 from markrickert/version-0.6-imagebuttons
Allow user to specify a UIImage as the title for a nav bar button item.
This commit is contained in:
@@ -250,6 +250,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
|
||||
@@ -290,7 +292,6 @@ class ProfileScreen < ProMotion::Screen
|
||||
self.user # => some_user instance
|
||||
end
|
||||
end
|
||||
|
||||
```
|
||||
|
||||
Closing a screen is as easy as can be.
|
||||
@@ -570,12 +571,14 @@ end
|
||||
<td>set_nav_bar_left_button(title, args = {})</td>
|
||||
<td>
|
||||
Set a left nav bar button.<br />
|
||||
`title` can be a `String` or a `UIImage`.
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>set_nav_bar_right_button(title, args = {})</td>
|
||||
<td>
|
||||
Set a right nav bar button.<br />
|
||||
`title` can be a `String` or a `UIImage`.
|
||||
<img src="http://i.imgur.com/whbkc.png" />
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
2
Rakefile
2
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
|
||||
|
||||
@@ -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
|
||||
|
||||
BIN
resources/list.png
Executable file
BIN
resources/list.png
Executable file
Binary file not shown.
|
After Width: | Height: | Size: 104 B |
@@ -4,10 +4,10 @@ class HomeScreen < ProMotion::Screen
|
||||
|
||||
def on_load
|
||||
set_nav_bar_right_button "Save", action: :save_something, type: UIBarButtonItemStyleDone
|
||||
set_nav_bar_left_button "Cancel", action: :return_to_some_other_screen, type: UIBarButtonItemStylePlain
|
||||
set_nav_bar_left_button UIImage.imageNamed("list.png"), action: :return_to_some_other_screen, type: UIBarButtonItemStylePlain
|
||||
end
|
||||
|
||||
def on_return(args={})
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
@@ -35,25 +35,39 @@ describe "screen helpers" do
|
||||
@screen.add_to @subview, sub_subview, { backgroundColor: UIColor.redColor }
|
||||
@subview.subviews.last.backgroundColor.should == UIColor.redColor
|
||||
end
|
||||
|
||||
|
||||
end
|
||||
|
||||
describe "nav bar buttons" do
|
||||
|
||||
|
||||
before do
|
||||
@screen = HomeScreen.new(nav_bar: true)
|
||||
end
|
||||
|
||||
|
||||
it "should add a left nav bar button" do
|
||||
@screen.set_nav_bar_left_button "Save", action: :save_something, type: UIBarButtonItemStyleDone
|
||||
@screen.navigationItem.leftBarButtonItem.class.should == UIBarButtonItem
|
||||
end
|
||||
|
||||
|
||||
it "should add a right nav bar button" do
|
||||
@screen.set_nav_bar_right_button "Cancel", action: :return_to_some_other_screen, type: UIBarButtonItemStylePlain
|
||||
@screen.navigationItem.rightBarButtonItem.class.should == UIBarButtonItem
|
||||
end
|
||||
|
||||
|
||||
it "should add an image right nav bar button" do
|
||||
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
|
||||
|
||||
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
|
||||
|
||||
Reference in New Issue
Block a user