mirror of
https://github.com/zhigang1992/rmq.git
synced 2026-01-12 17:52:17 +08:00
Adds t,b,l,r options to resource_resizable
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user