Class: UnderOs::UI::Image

Inherits:
View
  • Object
show all
Defined in:
lib/under_os/ui/image.rb

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ Image

Returns a new instance of Image.



4
5
6
7
8
9
10
11
12
# File 'lib/under_os/ui/image.rb', line 4

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

Instance Method Details

#load(url, options = {}, &complete) ⇒ Object



24
25
26
27
28
29
30
# File 'lib/under_os/ui/image.rb', line 24

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

#srcObject



14
15
16
# File 'lib/under_os/ui/image.rb', line 14

def src
  @_.image
end

#src=(src) ⇒ Object



18
19
20
21
22
# File 'lib/under_os/ui/image.rb', line 18

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