Sha256: e165336b4859ed78b7955cec09d8c603daeb7db4a064420fe8e9400931c76067

Contents?: true

Size: 760 Bytes

Versions: 3

Compression:

Stored size: 760 Bytes

Contents

class UnderOs::UI::Image < UnderOs::UI::View
  wraps UIImageView, tag: 'img'

  def initialize(options)
    options = {srs: options} unless options.is_a?(Hash)

    super(options)

    @_.contentMode = UIViewContentModeScaleAspectFit

    self.src = options.delete(:src) if options.has_key?(:src)
  end

  def src
    @_.image
  end

  def src=(src)
    src = UIImage.imageNamed(src)    if src.is_a?(String)
    src = UIImage.imageWithData(src) if src.is_a?(NSData)
    @_.image = src
  end

  def load(url, options={}, &complete)
    UnderOs::HTTP.get(url, options) do |response|
      self.src = response.data
      complete.call(response) if complete && complete.arity != 0
      complete.call           if complete && complete.arity == 0
    end
  end
end

Version data entries

3 entries across 3 versions & 2 rubygems

Version Path
under-os-ui-1.4.0 lib/under_os/ui/image.rb
under-os-1.3.0 lib/under_os/ui/image.rb
under-os-1.2.1 lib/under_os/ui/image.rb