lib/ios/sugarcube-568/uiimage.rb in sugarcube-2.8.1 vs lib/ios/sugarcube-568/uiimage.rb in sugarcube-2.8.2

- old
+ new

@@ -1,32 +1,41 @@ class UIImage class << self - SugarCube568_TallSuffix = '-568h@2x' + SugarCube568_TallSuffix = '-568h@2x' # 320 x 568 + SugarCube667_TallSuffix = '-667h@2x' # 375 x 667 + SugarCube736_TallSuffix = '-736h@2x' # 414 x 736 - def imageNamed568(name) - @may_use_taller_images ||= CGSizeEqualToSize(CGSizeMake(320, 568), UIScreen.mainScreen.bounds.size) - if ( @may_use_taller_images && name.length > 0 && name.rangeOfString(SugarCube568_TallSuffix).location == NSNotFound ) + def sugarcube568_imageNamed(name) + case UIScreen.mainScreen.bounds.size.height + when 568 + taller_image_ext = SugarCube568_TallSuffix + when 667 + taller_image_ext = SugarCube667_TallSuffix + when 736 + taller_image_ext = SugarCube736_TallSuffix + else + taller_image_ext = false + end + + if ( taller_image_ext && name.length > 0 && name.rangeOfString(taller_image_ext).location == NSNotFound ) # Check if is there a path extension or not - test_name = name; + test_name = name if test_name.pathExtension.length > 0 - test_name = test_name.stringByDeletingPathExtension.stringByAppendingString(SugarCube568_TallSuffix).stringByAppendingPathExtension(name.pathExtension) + test_name = test_name.stringByDeletingPathExtension.stringByAppendingString(taller_image_ext).stringByAppendingPathExtension(name.pathExtension) else - test_name = test_name.stringByAppendingString(SugarCube568_TallSuffix + ".png") + test_name = test_name.stringByAppendingString(taller_image_ext) end - image = imageNamed_old(test_name) - if image - return self.imageWithCGImage(image.CGImage, scale:2.0, orientation:image.imageOrientation) - end + return imageNamed_old(test_name) end return nil end alias :imageNamed_old :imageNamed -# now we've got imageNamed568 and imageNamed_old to load the respective versions + # now we've got sugarcube568_imageNamed and imageNamed_old to load the respective versions def imageNamed(name) - imageNamed568(name) || imageNamed_old(name) + sugarcube568_imageNamed(name) || imageNamed_old(name) end end end