Sha256: e750c085b33b35d6f55213a43effd109b1aa0d28744b2e6d679b928e5f32162d

Contents?: true

Size: 1.26 KB

Versions: 2

Compression:

Stored size: 1.26 KB

Contents

module MotionPrime
  module SupportControlContentAlignment
    VERTICAL_ALIGNMENT_CONSTS = {
      UIControlContentVerticalAlignmentCenter => :center,
      UIControlContentVerticalAlignmentTop => :top,
      UIControlContentVerticalAlignmentBottom => :bottom,
      UIControlContentVerticalAlignmentFill => :fill # TODO: handle this value
    }
    def setContentVerticalAlignment(value)
      return unless @_content_vertical_alignment = VERTICAL_ALIGNMENT_CONSTS[value]
      super
    end

    def padding_top
      padding_top = self.paddingTop || self.padding
      if @_content_vertical_alignment == :bottom
        padding_bottom = self.paddingBottom || self.padding
        bounds_height - padding_bottom.to_i - line_height
      elsif @_content_vertical_alignment == :top
        padding_top.to_i
      else # center label
        padding_top_offset = padding_top.to_i - (self.paddingBottom || self.padding).to_i
        (bounds_height - line_height)/2 + padding_top_offset
        # TODO: check in which cases we should add `1` here
      end
    end

    def padding_bottom
      (bounds_height - (line_height + padding_top))
    end

    def line_height
      @_line_height || self.font.pointSize
    end

    def bounds_height
      self.bounds.size.height
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
motion-prime-1.0.0 motion-prime/support/_control_content_alignment.rb
motion-prime-0.9.9.2 motion-prime/support/_control_content_alignment.rb