Class: Tgios::LoadingView

Inherits:
UIView
  • Object
show all
Defined in:
lib/tgios/loading_indicator.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#load_countObject

Returns the value of attribute load_count.



4
5
6
# File 'lib/tgios/loading_indicator.rb', line 4

def load_count
  @load_count
end

Class Method Details

.add_loading_view_to(view) ⇒ Object



33
34
35
36
37
# File 'lib/tgios/loading_indicator.rb', line 33

def self.add_loading_view_to(view)
  loading_view = LoadingView.alloc.initWithFrame(view.bounds)
  CommonUIUtility.add_full_subview(view, loading_view)
  loading_view
end

Instance Method Details

#initWithFrame(frame) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/tgios/loading_indicator.rb', line 6

def initWithFrame(frame)
  if super
    @load_count = 0
    self.hidden = true
    base_view = Base.style(UIView.new, backgroundColor: :black.uicolor, alpha: 0.5)

    @indicator = UIActivityIndicatorView.large
    [{super_view: self, subview: base_view}, {super_view: self, subview: @indicator}].each do |hash|
      CommonUIUtility.add_full_subview(hash[:super_view], hash[:subview])
    end
    @label = Base.style(UILabel.new,
                        frame: self.bounds,
                        font: lambda {UIFont.systemFontOfSize(22)},
                        textAlignment: :center.uialignment,
                        backgroundColor: :clear.uicolor,
                        textColor: :white.uicolor)
    @label.sizeToFit
    Motion::Layout.new do |l|
      l.view self
      l.subviews 'label' => @label
      l.vertical '[label]-290-|'
      l.horizontal '|-20-[label]-20-|'
    end
  end
  self
end

#start_loading(text = '', force = false) ⇒ Object



39
40
41
42
43
44
45
46
# File 'lib/tgios/loading_indicator.rb', line 39

def start_loading(text='', force=false)
  @label.text = text
  if @load_count <= 0 || force
    self.hidden = false
    @indicator.startAnimating
  end
  @load_count += 1
end

#stop_loading(force = false) ⇒ Object



48
49
50
51
52
53
54
# File 'lib/tgios/loading_indicator.rb', line 48

def stop_loading(force=false)
  @load_count -=1
  if @load_count <= 0 || force
    self.hidden = true
    @indicator.stopAnimating
  end
end