Class: NSAttributedString
- Defined in:
- lib/sugarcube-uikit/nsattributedstring.rb,
lib/sugarcube-attributedstring/nsattributedstring.rb
Instance Method Summary collapse
- #+(attributedstring) ⇒ Object
- #background_color(value) ⇒ Object (also: #bg_color)
- #bold(size = nil) ⇒ Object
- #dummy ⇒ Object
- #font(value) ⇒ Object
- #foreground_color(value) ⇒ Object (also: #color)
- #italic(size = nil) ⇒ Object
- #kern(value) ⇒ Object
- #ligature(value) ⇒ Object
- #nsattributedstring ⇒ Object
- #paragraph_style(value) ⇒ Object
- #shadow(value) ⇒ Object
- #strikethrough_style(value) ⇒ Object
- #stroke_color(value) ⇒ Object
- #stroke_width(value) ⇒ Object
- #to_s ⇒ Object
- #uilabel ⇒ UILabel
- #underline ⇒ Object
- #underline_style(value) ⇒ Object
- #vertical_glyph_form(value) ⇒ Object
- #with_attributes(attributes) ⇒ Object
Instance Method Details
#+(attributedstring) ⇒ Object
143 144 145 |
# File 'lib/sugarcube-attributedstring/nsattributedstring.rb', line 143 def +(attributedstring) NSMutableAttributedString.alloc.initWithAttributedString(self) + attributedstring.nsattributedstring end |
#background_color(value) ⇒ Object Also known as: bg_color
100 101 102 |
# File 'lib/sugarcube-attributedstring/nsattributedstring.rb', line 100 def background_color(value) with_attributes({NSBackgroundColorAttributeName => value.uicolor}) end |
#bold(size = nil) ⇒ Object
69 70 71 72 |
# File 'lib/sugarcube-attributedstring/nsattributedstring.rb', line 69 def bold(size=nil) font = :bold.uifont(size) self.font(font) end |
#dummy ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/sugarcube-attributedstring/nsattributedstring.rb', line 42 def dummy # make sure NSAttributedString constants get compiled foo = NSFontAttributeName foo = NSParagraphStyleAttributeName foo = NSForegroundColorAttributeName foo = NSBackgroundColorAttributeName foo = NSLigatureAttributeName foo = NSKernAttributeName foo = NSStrikethroughStyleAttributeName foo = NSUnderlineStyleAttributeName foo = NSStrokeColorAttributeName foo = NSStrokeWidthAttributeName foo = NSShadowAttributeName foo = NSVerticalGlyphFormAttributeName # make sure alignments get compiled foo = NSLeftTextAlignment foo = NSRightTextAlignment foo = NSCenterTextAlignment foo = NSJustifiedTextAlignment foo = NSNaturalTextAlignment nil end |
#font(value) ⇒ Object
83 84 85 |
# File 'lib/sugarcube-attributedstring/nsattributedstring.rb', line 83 def font(value) with_attributes({NSFontAttributeName => value.uifont}) end |
#foreground_color(value) ⇒ Object Also known as: color
91 92 93 |
# File 'lib/sugarcube-attributedstring/nsattributedstring.rb', line 91 def foreground_color(value) with_attributes({NSForegroundColorAttributeName => value.uicolor}) end |
#italic(size = nil) ⇒ Object
74 75 76 77 |
# File 'lib/sugarcube-attributedstring/nsattributedstring.rb', line 74 def italic(size=nil) font = :italic.uifont(size) self.font(font) end |
#kern(value) ⇒ Object
109 110 111 |
# File 'lib/sugarcube-attributedstring/nsattributedstring.rb', line 109 def kern(value) with_attributes({NSKernAttributeName => value}) end |
#ligature(value) ⇒ Object
105 106 107 |
# File 'lib/sugarcube-attributedstring/nsattributedstring.rb', line 105 def ligature(value) with_attributes({NSLigatureAttributeName => value}) end |
#nsattributedstring ⇒ Object
139 140 141 |
# File 'lib/sugarcube-attributedstring/nsattributedstring.rb', line 139 def nsattributedstring self end |
#paragraph_style(value) ⇒ Object
87 88 89 |
# File 'lib/sugarcube-attributedstring/nsattributedstring.rb', line 87 def paragraph_style(value) with_attributes({NSParagraphStyleAttributeName => value}) end |
#shadow(value) ⇒ Object
125 126 127 |
# File 'lib/sugarcube-attributedstring/nsattributedstring.rb', line 125 def shadow(value) with_attributes({NSShadowAttributeName => value}) end |
#strikethrough_style(value) ⇒ Object
121 122 123 |
# File 'lib/sugarcube-attributedstring/nsattributedstring.rb', line 121 def strikethrough_style(value) with_attributes({NSStrikethroughStyleAttributeName => value}) end |
#stroke_color(value) ⇒ Object
117 118 119 |
# File 'lib/sugarcube-attributedstring/nsattributedstring.rb', line 117 def stroke_color(value) with_attributes({NSStrokeColorAttributeName => value.uicolor}) end |
#stroke_width(value) ⇒ Object
113 114 115 |
# File 'lib/sugarcube-attributedstring/nsattributedstring.rb', line 113 def stroke_width(value) with_attributes({NSStrokeWidthAttributeName => value}) end |
#to_s ⇒ Object
65 66 67 |
# File 'lib/sugarcube-attributedstring/nsattributedstring.rb', line 65 def to_s string # this is the name of the Cocoa method to return an NSString end |
#uilabel ⇒ UILabel
4 5 6 7 8 9 10 |
# File 'lib/sugarcube-uikit/nsattributedstring.rb', line 4 def uilabel UILabel.alloc.initWithFrame([[0, 0], [0, 0]]).tap do |label| label.attributedText = self label.backgroundColor = :clear.uicolor label.sizeToFit end end |
#underline ⇒ Object
79 80 81 |
# File 'lib/sugarcube-attributedstring/nsattributedstring.rb', line 79 def underline underline_style(NSUnderlineStyleSingle) end |
#underline_style(value) ⇒ Object
96 97 98 |
# File 'lib/sugarcube-attributedstring/nsattributedstring.rb', line 96 def underline_style(value) with_attributes({NSUnderlineStyleAttributeName => value}) end |
#vertical_glyph_form(value) ⇒ Object
129 130 131 |
# File 'lib/sugarcube-attributedstring/nsattributedstring.rb', line 129 def vertical_glyph_form(value) with_attributes({NSVerticalGlyphFormAttributeName => value}) end |
#with_attributes(attributes) ⇒ Object
133 134 135 136 137 |
# File 'lib/sugarcube-attributedstring/nsattributedstring.rb', line 133 def with_attributes(attributes) retval = NSMutableAttributedString.alloc.initWithAttributedString(self) retval.addAttributes(attributes, range:[0, self.length]) retval end |