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
- #letterpress ⇒ 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
150 151 152 |
# File 'lib/sugarcube-attributedstring/nsattributedstring.rb', line 150 def +(attributedstring) NSMutableAttributedString.alloc.initWithAttributedString(self) + attributedstring.nsattributedstring end |
#background_color(value) ⇒ Object Also known as: bg_color
103 104 105 |
# File 'lib/sugarcube-attributedstring/nsattributedstring.rb', line 103 def background_color(value) with_attributes({NSBackgroundColorAttributeName => value.uicolor}) end |
#bold(size = nil) ⇒ Object
72 73 74 75 |
# File 'lib/sugarcube-attributedstring/nsattributedstring.rb', line 72 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 64 65 66 |
# 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 # new iOS 7 text effects foo = NSTextEffectsAttributeName foo = NSTextEffectsLetterPressStyle # make sure alignments get compiled foo = NSLeftTextAlignment foo = NSRightTextAlignment foo = NSCenterTextAlignment foo = NSJustifiedTextAlignment foo = NSNaturalTextAlignment nil end |
#font(value) ⇒ Object
86 87 88 |
# File 'lib/sugarcube-attributedstring/nsattributedstring.rb', line 86 def font(value) with_attributes({NSFontAttributeName => value.uifont}) end |
#foreground_color(value) ⇒ Object Also known as: color
94 95 96 |
# File 'lib/sugarcube-attributedstring/nsattributedstring.rb', line 94 def foreground_color(value) with_attributes({NSForegroundColorAttributeName => value.uicolor}) end |
#italic(size = nil) ⇒ Object
77 78 79 80 |
# File 'lib/sugarcube-attributedstring/nsattributedstring.rb', line 77 def italic(size=nil) font = :italic.uifont(size) self.font(font) end |
#kern(value) ⇒ Object
112 113 114 |
# File 'lib/sugarcube-attributedstring/nsattributedstring.rb', line 112 def kern(value) with_attributes({NSKernAttributeName => value}) end |
#letterpress ⇒ Object
136 137 138 |
# File 'lib/sugarcube-attributedstring/nsattributedstring.rb', line 136 def letterpress with_attributes({NSTextEffectsAttributeName => NSTextEffectsLetterPressStyle}) end |
#ligature(value) ⇒ Object
108 109 110 |
# File 'lib/sugarcube-attributedstring/nsattributedstring.rb', line 108 def ligature(value) with_attributes({NSLigatureAttributeName => value}) end |
#nsattributedstring ⇒ Object
146 147 148 |
# File 'lib/sugarcube-attributedstring/nsattributedstring.rb', line 146 def nsattributedstring self end |
#paragraph_style(value) ⇒ Object
90 91 92 |
# File 'lib/sugarcube-attributedstring/nsattributedstring.rb', line 90 def paragraph_style(value) with_attributes({NSParagraphStyleAttributeName => value}) end |
#shadow(value) ⇒ Object
128 129 130 |
# File 'lib/sugarcube-attributedstring/nsattributedstring.rb', line 128 def shadow(value) with_attributes({NSShadowAttributeName => value}) end |
#strikethrough_style(value) ⇒ Object
124 125 126 |
# File 'lib/sugarcube-attributedstring/nsattributedstring.rb', line 124 def strikethrough_style(value) with_attributes({NSStrikethroughStyleAttributeName => value}) end |
#stroke_color(value) ⇒ Object
120 121 122 |
# File 'lib/sugarcube-attributedstring/nsattributedstring.rb', line 120 def stroke_color(value) with_attributes({NSStrokeColorAttributeName => value.uicolor}) end |
#stroke_width(value) ⇒ Object
116 117 118 |
# File 'lib/sugarcube-attributedstring/nsattributedstring.rb', line 116 def stroke_width(value) with_attributes({NSStrokeWidthAttributeName => value}) end |
#to_s ⇒ Object
68 69 70 |
# File 'lib/sugarcube-attributedstring/nsattributedstring.rb', line 68 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
82 83 84 |
# File 'lib/sugarcube-attributedstring/nsattributedstring.rb', line 82 def underline underline_style(NSUnderlineStyleSingle) end |
#underline_style(value) ⇒ Object
99 100 101 |
# File 'lib/sugarcube-attributedstring/nsattributedstring.rb', line 99 def underline_style(value) with_attributes({NSUnderlineStyleAttributeName => value}) end |
#vertical_glyph_form(value) ⇒ Object
132 133 134 |
# File 'lib/sugarcube-attributedstring/nsattributedstring.rb', line 132 def vertical_glyph_form(value) with_attributes({NSVerticalGlyphFormAttributeName => value}) end |
#with_attributes(attributes) ⇒ Object
140 141 142 143 144 |
# File 'lib/sugarcube-attributedstring/nsattributedstring.rb', line 140 def with_attributes(attributes) retval = NSMutableAttributedString.alloc.initWithAttributedString(self) retval.addAttributes(attributes, range:[0, self.length]) retval end |