Method: UIImage#scale_to_fill

Defined in:
lib/sugarcube-image/uiimage.rb,
lib/sugarcube-image/uiimage.rb,
lib/sugarcube-image/uiimage.rb,
lib/sugarcube-image/uiimage.rb

#scale_to_fill(new_size, position: position, scale: scale) ⇒ UIImage

Scales an image to fit within the given size, stretching one or both dimensions so that it completely fills the area. The current aspect ratio is maintained. If you want to place an image inside a container image, this is the method to use.

You can specify a position property, which can be a symbol or a point. It specifies where you want the image located if it has to be cropped. Specifying the top-left corner will display the top-left corner of the image, likewise specifing the bottom-right corner will display that corner. If you want the image centered, you can use the 'position-less' version of this method (scale_to_fit()) or specify the point at the center of the image (scale_to_fit(size, position:[w/2, h/2])), or use a symbol (scale_to_fit(size, position: :center)).

@param scale [Numeric] image scale

Parameters:

  • new_size (CGSize)

    Minimum dimensions of desired image. The returned image is guaranteed to fit within these dimensions.

  • position (Symbol, CGPoint) (defaults to: position)

    Where to position the resized image. Valid symbols are: [:top_left, :top, :top_right, :left, :center, :right, :bottom_left, :bottom, :bottom_right] (if you forget the underscore, like topleft, that'll work, too)

Returns:



65
66
67
# File 'lib/sugarcube-image/uiimage.rb', line 65

def scale_to_fill(new_size)
  scale_to_fill(new_size, position: :center)
end