Sha256: a546783c7ed99889d84dfff6b2d5f9c18587bba1a30f0939ce129d2377c4d2d4

Contents?: true

Size: 1.43 KB

Versions: 25

Compression:

Stored size: 1.43 KB

Contents

class UIImage
  class << self
    SugarCube568_TallSuffix = '-568h@2x'  # 320 x 568
    SugarCube667_TallSuffix = '-667h@2x'  # 375 x 667
    SugarCube736_TallSuffix = '-736h@2x'  # 414 x 736
    SugarCube1024_TallSuffix = '-1024h@2x'  # 768 x 1024

    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
      when 1024
        taller_image_ext = SugarCube1024_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
        if test_name.pathExtension.length > 0
          test_name = test_name.stringByDeletingPathExtension.stringByAppendingString(taller_image_ext).stringByAppendingPathExtension(name.pathExtension)
        else
          test_name = test_name.stringByAppendingString(taller_image_ext)
        end

        return imageNamed_old(test_name)
      end

      return nil
    end

    alias :imageNamed_old :imageNamed
    # now we've got sugarcube568_imageNamed and imageNamed_old to load the respective versions

    def imageNamed(name)
      sugarcube568_imageNamed(name) || imageNamed_old(name)
    end
  end
end

Version data entries

25 entries across 25 versions & 1 rubygems

Version Path
sugarcube-4.0.0 lib/ios/sugarcube-568/uiimage.rb
sugarcube-3.5.0 lib/ios/sugarcube-568/uiimage.rb
sugarcube-3.4.2 lib/ios/sugarcube-568/uiimage.rb
sugarcube-3.4.1 lib/ios/sugarcube-568/uiimage.rb
sugarcube-3.4.0 lib/ios/sugarcube-568/uiimage.rb
sugarcube-3.3.7 lib/ios/sugarcube-568/uiimage.rb
sugarcube-3.3.6 lib/ios/sugarcube-568/uiimage.rb
sugarcube-3.3.5 lib/ios/sugarcube-568/uiimage.rb
sugarcube-3.3.4 lib/ios/sugarcube-568/uiimage.rb
sugarcube-3.3.3 lib/ios/sugarcube-568/uiimage.rb
sugarcube-3.3.2 lib/ios/sugarcube-568/uiimage.rb
sugarcube-3.3.1 lib/ios/sugarcube-568/uiimage.rb
sugarcube-3.3.0 lib/ios/sugarcube-568/uiimage.rb
sugarcube-3.2.0 lib/ios/sugarcube-568/uiimage.rb
sugarcube-3.1.1 lib/ios/sugarcube-568/uiimage.rb
sugarcube-3.1.0 lib/ios/sugarcube-568/uiimage.rb
sugarcube-3.0.8 lib/ios/sugarcube-568/uiimage.rb
sugarcube-3.0.7 lib/ios/sugarcube-568/uiimage.rb
sugarcube-3.0.6 lib/ios/sugarcube-568/uiimage.rb
sugarcube-3.0.5 lib/ios/sugarcube-568/uiimage.rb