Adds t,b,l,r options to resource_resizable

This commit is contained in:
David Larrabee
2014-11-01 20:29:50 -04:00
parent 5de3b6db64
commit 72fd4e8bac
2 changed files with 26 additions and 4 deletions

View File

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

View File

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