Class: BW::UIBarButtonItem

Inherits:
UIBarButtonItem
  • Object
show all
Defined in:
motion/ui/ui_bar_button_item.rb

Class Method Summary collapse

Class Method Details

.build(options = {}, &block) ⇒ Object



74
75
76
77
# File 'motion/ui/ui_bar_button_item.rb', line 74

def build(options = {}, &block)
  NSLog "[DEPRECATED - BW::UIBarButtonItem.build] please use .new instead."
  new(options, &block)
end

.custom(view, &block) ⇒ Object



55
56
57
58
# File 'motion/ui/ui_bar_button_item.rb', line 55

def custom(view, &block)
  view.when_tapped(true, &block) if block
  alloc.initWithCustomView(view)
end

.new(options = {}, &block) ⇒ Object

Raises:

  • (ArgumentError)


60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'motion/ui/ui_bar_button_item.rb', line 60

def new(options = {}, &block)
  if options[:styled]
    args = options.values_at(:title, :image, :landscape).compact
    return styled(options[:styled], *args, &block)
  end

  return system(options[:system], &block) if options[:system]

  return custom(options[:custom], &block) if options[:custom]
  return custom(options[:view],   &block) if options[:view]

  raise ArgumentError, "invalid options - #{options.inspect}"
end

.styled(type, *objects, &block) ⇒ Object



4
5
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
32
33
34
35
36
37
38
39
# File 'motion/ui/ui_bar_button_item.rb', line 4

def styled(type, *objects, &block)
  if block.nil?
    action = nil
  else
    block.weak! if BubbleWrap.use_weak_callbacks?
    action = :call
  end
  object = objects.size == 1 ? objects.first : objects
  style  = Constants.get("UIBarButtonItemStyle", type)

  item = if object.is_a?(String)
    alloc.initWithTitle(object,
      style:style,
      target:block,
      action:action
    )
  elsif object.is_a?(UIImage)
    alloc.initWithImage(object,
      style:style,
      target:block,
      action:action
    )
  elsif object.is_a?(Array) && object.size == 2 && object.all? { |o| o.is_a?(UIImage) }
    alloc.initWithImage(object[0],
      landscapeImagePhone:object[1],
      style:style,
      target:block,
      action:action
    )
  else
    raise ArgumentError, "invalid object - #{object.inspect}"
  end

  item.instance_variable_set(:@target, block)
  item
end

.system(type, &block) ⇒ Object



41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'motion/ui/ui_bar_button_item.rb', line 41

def system(type, &block)
  if block.nil?
    action = nil
  else
    block.weak! if BubbleWrap.use_weak_callbacks?
    action = :call
  end
  system_item = Constants.get("UIBarButtonSystemItem", type)

  item = alloc.initWithBarButtonSystemItem(system_item, target:block, action:action)
  item.instance_variable_set(:@target, block)
  item
end