Conflicts:
	lib/ProMotion/screens/_screen_module.rb
This commit is contained in:
Steve Ross
2013-05-16 11:34:02 -07:00
6 changed files with 33 additions and 12 deletions

View File

@@ -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
@@ -250,6 +252,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 +294,6 @@ class ProfileScreen < ProMotion::Screen
self.user # => some_user instance
end
end
```
Closing a screen is as easy as can be.
@@ -570,12 +573,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>

View File

@@ -1,5 +1,5 @@
$:.unshift("/Library/RubyMotion/lib")
require 'motion/project'
require 'motion/project/template/ios'
require 'bundler/gem_tasks'
Bundler.setup
Bundler.require

View File

@@ -78,8 +78,10 @@ module ProMotion
args[:target] ||= self
args[:action] ||= nil
if args[:system_icon]
button = UIBarButtonItem.alloc.initWithBarButtonSystemItem(args[:system_icon], target: args[:target], action: args[:action])
button = UIBarButtonItem.alloc.initWithBarButtonSystemItem(args[:system_icon], target: args[:target], action: args[:action]) if args[:system_icon]
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

BIN
resources/list.png Executable file

Binary file not shown.

After

Width:  |  Height:  |  Size: 104 B

View File

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

View File

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