Class: Walt::TextAsset
Constant Summary collapse
- PROPERTIES =
[:text, :text_color, :background_color, :number_of_lines, :font, :attributes, :text_alignment]
Instance Method Summary collapse
-
#initialize(params = {}) ⇒ TextAsset
constructor
A new instance of TextAsset.
- #view ⇒ Object
Methods inherited from Asset
#content_mode=, for, #on_ready, #view_content_mode
Methods included from Support::AttrDefault
Constructor Details
#initialize(params = {}) ⇒ TextAsset
Returns a new instance of TextAsset.
24 25 26 27 28 29 30 31 32 |
# File 'lib/walt/asset/text.rb', line 24 def initialize(params = {}) super params.is_a?(NSDictionary) && params.each do |key, value| if PROPERTIES.include?(key.to_sym) self.send("#{key}=", value) end end end |
Instance Method Details
#view ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/walt/asset/text.rb', line 34 def view @view ||= UILabel.alloc.initWithFrame(CGRectZero).tap do |view| view.frame = [self.position || CGPointZero, self.size || CGSizeZero] view.contentMode = self.view_content_mode view.clipsToBounds = self.clips_to_bounds view.text = self.text view.textColor = self.text_color.to_color view.backgroundColor = self.background_color.to_color view.numberOfLines = self.number_of_lines view.font = Walt::Font.make(self.font) if self.font view.textAlignment = Walt::Support.constant("UITextAlignment", self.text_alignment) if self.text_alignment if self.attributes attributes = Walt::Font.attributes(self.attributes) view.font = attributes[UITextAttributeFont] if attributes[UITextAttributeFont] view.textColor = attributes[UITextAttributeTextColor] if attributes[UITextAttributeTextColor] view.shadowColor = attributes[UITextAttributeTextShadowColor] if attributes[UITextAttributeTextShadowColor] if attributes[UITextAttributeTextShadowOffset] view.shadowOffset = CGSizeMake(self.attributes[:shadow_offset][:x], self.attributes[:shadow_offset][:y]) end end if !self.size view.sizeToFit end Dispatch::Queue.main.async do self.on_ready(true) end end end |