Sha256: e1adf500fd16a1323ef0f915a2a284f8e28fc452a89759815d0a53ddce172eeb
Contents?: true
Size: 1.46 KB
Versions: 1
Compression:
Stored size: 1.46 KB
Contents
# This class have some modifications for UITextField: # * support padding, padding_left, padding_right options # * support placeholder_color, placeholder_font options class DMTextField < UITextField include MotionPrime::SupportKeyValueStore include MotionPrime::SupportPaddingAttribute attr_accessor :placeholderColor, :placeholderFont # placeholder position def textRectForBounds(bounds) calculate_rect_for(bounds) end # text position def editingRectForBounds(bounds) calculate_rect_for(bounds) end def drawPlaceholderInRect(rect) color = self.placeholderColor || :gray.uicolor color.setFill font = self.placeholderFont || self.font || :system.uifont(16) self.placeholder.drawInRect(rect, withFont: font) 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 + 2 end end def self.default_padding_left 5 end def self.default_padding_right 5 end private def calculate_rect_for(bounds) height_diff = self.bounds.size.height - (self.font.pointSize + padding_top*2) bounds = CGRectMake(bounds.origin.x, bounds.origin.y, bounds.size.width, bounds.size.height - height_diff) CGRectMake( bounds.origin.x + padding_left, bounds.origin.y + padding_top, bounds.size.width - (padding_left + padding_right), bounds.size.height - padding_top*2) end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
motion-prime-0.3.2 | motion-prime/support/dm_text_field.rb |