diff --git a/motion/ruby_motion_query/image.rb b/motion/ruby_motion_query/image.rb index f859ba6..b378b6f 100644 --- a/motion/ruby_motion_query/image.rb +++ b/motion/ruby_motion_query/image.rb @@ -42,10 +42,14 @@ module RubyMotionQuery # # @return [UIImage] def resource_resizable(file_base_name, opts) - # TODO, also alloow short syntax, t: instead of top: etc - ext = opts[:ext] || DEFAULT_IMAGE_EXT image = resource(file_base_name, opts) - image.resizableImageWithCapInsets([opts[:top], opts[:left], opts[:bottom], opts[:right]], resizingMode: UIImageResizingModeStretch) + + frame = [ opts[:top] || opts[:t], + opts[:left] || opts[:l], + opts[:bottom] || opts[:b], + opts[:right] || opts[:r] + ] + image.resizableImageWithCapInsets(frame, resizingMode: UIImageResizingModeStretch) end # Note: FROM Sugarcube, thanks Sugarcube diff --git a/spec/image.rb b/spec/image.rb index 2f802ba..d0fbe46 100644 --- a/spec/image.rb +++ b/spec/image.rb @@ -18,5 +18,23 @@ describe 'image' do image.scale.should == UIScreen.mainScreen.scale end - # TODO test resource with and without caching, resource_for_device, and resource_resizable + describe "resource_resizable" do + it "should return an image with the proper cap insets" do + opts = { top: 1, left: 1, bottom: 1, right: 1 } + image = @rmq.image.resource_resizable('logo', opts) + + image.is_a?(UIImage).should.be.true + image.capInsets.should == UIEdgeInsetsMake(1.0, 1.0, 1.0, 1.0) + end + + it "should accept the shortcut labels for position as well" do + opts = { t: 1, l: 1, b: 1, r: 1 } + image = @rmq.image.resource_resizable('logo', opts) + + image.is_a?(UIImage).should.be.true + image.capInsets.should == UIEdgeInsetsMake(1.0, 1.0, 1.0, 1.0) + end + end + + # TODO test resource with and without caching, resource_for_device end