class BW::UIBarButtonItem

Public Class Methods

build(options = {}, &block) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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