Sha256: 297daab1001ec7616ba4ce3f248a1547b7ae4fa82e08b9a6ed4fb8d1e755270f

Contents?: true

Size: 1.5 KB

Versions: 1

Compression:

Stored size: 1.5 KB

Contents

module MotionWizard
  class WizardNavigationBar < UIView
    def init_with_number_of_steps(number_of_steps, wizard_controller)
      self.init
      @number_of_steps = number_of_steps
      @index_items = []
      @wizard_controller = WeakRef.new(wizard_controller)
      create_index_items
      self
    end

    def create_index_items
      @number_of_steps.times do |i|
        index_item = @wizard_controller.create_index_item_at(i)
        @index_items << index_item
        addSubview(index_item)
      end
    end

    def select(index)
      @index_items[@selected_step].unselect if @selected_step && @index_items[@selected_step].respond_to?(:unselect)
      @selected_step = index
      @index_items[@selected_step].select if @selected_step && @index_items[@selected_step].respond_to?(:select)
    end

    def setFrame(frame)
      super
      resize_indexes
    end

    def reset!
      remove_all_index_items
      create_index_items
      resize_indexes
    end

    def remove_all_index_items
      @index_items.each{|i| i.removeFromSuperview}
      @index_items.clear
    end

    def resize_indexes
      return unless @number_of_steps
      index_width = (self.frame.size.width).to_f / @number_of_steps
      @index_items.each_with_index do |index_item, i|
        index_item.frame = [[index_width*i, 0], [index_width, self.size.height]]
        setup_index_item_at(index_item, i)
      end
    end

    def setup_index_item_at(index_item, i)
      @wizard_controller.setup_index_item_at(index_item, i)
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
motion-wizard-0.1 lib/motion-wizard/views/wizard_navigation_bar.rb