Sha256: 0918cd2bf74d3015c059233e45a1d3cb2732b5fa99bb9b79817e4e344b85928c

Contents?: true

Size: 1.06 KB

Versions: 2

Compression:

Stored size: 1.06 KB

Contents

motion_require '../support/_key_value_store'
motion_require '../support/_padding_attribute'
class MPButton < UIButton
  include MotionPrime::SupportKeyValueStore
  include MotionPrime::SupportPaddingAttribute
  attr_accessor :sizeToFit

  def setTitle(value)
    setTitle value, forState: UIControlStateNormal
  end

  def setImage(value)
    setImage value, forState: UIControlStateNormal
  end

  def setTitleEdgeInsets(value)
    @custom_title_inset_drawn = true
    super
  end

  def self.default_padding_left
    5
  end

  def self.default_padding_right
    5
  end

  def padding_top # to center title label
    self.paddingTop || self.padding || begin
      single_line_height = self.font.pointSize
      (self.bounds.size.height - single_line_height)/2 + 1
    end
  end

  def padding_bottom
    self.bounds.size.height - (self.font.pointSize + padding_top)
  end

  def apply_padding!(rect)
    self.setTitleEdgeInsets(padding_insets)
  end

  def apply_padding?
    super && !@custom_title_inset_drawn
  end

  def drawRect(rect)
    apply_padding(rect)
    super
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
motion-prime-0.9.9 motion-prime/support/mp_button.rb
motion-prime-0.9.8 motion-prime/support/mp_button.rb