Sha256: 3d3fa5ebb71f32c66adf014eaeb74775a35f0c83953df4ce517b1c08009aee7a

Contents?: true

Size: 1.1 KB

Versions: 1

Compression:

Stored size: 1.1 KB

Contents

module ProMotion
  module ViewHelper
    def set_attributes(element, args = {})
      args.each do |k, v|
        if v.is_a? Hash
          # TODO: Do this recursively
          v.each do |k2, v2|
            sub_element = element.send("#{k}")
            sub_element.send("#{k2}=", v2) if sub_element.respond_to?("#{k2}=")
          end
        elsif v.is_a? Array
          element.send("#{k}", *v) if element.respond_to?("#{k}")
        else
          element.send("#{k}=", v) if element.respond_to?("#{k}=")
        end
      end
      element
    end

    def frame_from_array(array)
      return CGRectMake(array[0], array[1], array[2], array[3]) if array.length == 4
      Console.log(" - frame_from_array expects an array with four elements: [x, y, width, height]", with_color: Console::RED_COLOR)
      CGRectZero
    end

    def content_height(view)
      height = 0
      view.subviews.each do |sub_view|
        next if sub_view.isHidden
        y = sub_view.frame.origin.y
        h = sub_view.frame.size.height
        if (y + h) > height
          height = y + h
        end
      end
      height
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
ProMotion-0.5.2 lib/ProMotion/helpers/view_helper.rb