Class: NSAttributedString
- Defined in:
- lib/ios/sugarcube-ui/nsattributedstring.rb,
lib/ios/sugarcube-attributedstring/nsattributedstring.rb,
lib/osx/sugarcube-attributedstring/nsattributedstring.rb,
lib/cocoa/sugarcube-attributedstring/nsattributedstring.rb
Instance Method Summary collapse
- #+(attributedstring) ⇒ Object
- #attrd(attributes = nil) ⇒ Object
- #background_color(value) ⇒ Object (also: #bg_color)
- #bold(size = nil) ⇒ Object
- #empty? ⇒ Boolean
- #font(value) ⇒ Object
- #foreground_color(value) ⇒ Object (also: #color)
- #italic(size = nil) ⇒ Object
- #kern(value) ⇒ Object
- #letterpress ⇒ Object
- #ligature(value) ⇒ Object
- #nsattributedstring(attributes = nil) ⇒ Object
- #paragraph_style(value) ⇒ Object
- #shadow(value) ⇒ Object
- #strikethrough_style(value) ⇒ Object
- #strip ⇒ Object
- #stroke_color(value) ⇒ Object
- #stroke_width(value) ⇒ Object
- #subscript ⇒ Object
- #sugarcube_nsattributedstring_dummy_method ⇒ Object
- #superscript(amount = nil) ⇒ 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
108 109 110 111 112 |
# File 'lib/cocoa/sugarcube-attributedstring/nsattributedstring.rb', line 108 def +(attributedstring) string = NSMutableAttributedString.alloc.initWithAttributedString(self) string.appendAttributedString(attributedstring.nsattributedstring) string end |
#attrd(attributes = nil) ⇒ Object
104 105 106 |
# File 'lib/cocoa/sugarcube-attributedstring/nsattributedstring.rb', line 104 def attrd(attributes=nil) self.nsattributedstring(attributes=nil) end |
#background_color(value) ⇒ Object Also known as: bg_color
74 75 76 |
# File 'lib/ios/sugarcube-attributedstring/nsattributedstring.rb', line 74 def background_color(value) with_attributes({ NSBackgroundColorAttributeName => value.uicolor }) end |
#bold(size = nil) ⇒ Object
47 48 49 50 |
# File 'lib/ios/sugarcube-attributedstring/nsattributedstring.rb', line 47 def bold(size=nil) font = :bold.uifont(size) self.font(font) end |
#empty? ⇒ Boolean
114 115 116 |
# File 'lib/cocoa/sugarcube-attributedstring/nsattributedstring.rb', line 114 def empty? self.length == 0 end |
#font(value) ⇒ Object
57 58 59 |
# File 'lib/ios/sugarcube-attributedstring/nsattributedstring.rb', line 57 def font(value) with_attributes({ NSFontAttributeName => value.uifont }) end |
#foreground_color(value) ⇒ Object Also known as: color
69 70 71 |
# File 'lib/ios/sugarcube-attributedstring/nsattributedstring.rb', line 69 def foreground_color(value) with_attributes({ NSForegroundColorAttributeName => value.uicolor }) end |
#italic(size = nil) ⇒ Object
52 53 54 55 |
# File 'lib/ios/sugarcube-attributedstring/nsattributedstring.rb', line 52 def italic(size=nil) font = :italic.uifont(size) self.font(font) end |
#kern(value) ⇒ Object
70 71 72 |
# File 'lib/cocoa/sugarcube-attributedstring/nsattributedstring.rb', line 70 def kern(value) with_attributes({ NSKernAttributeName => value }) end |
#letterpress ⇒ Object
92 93 94 |
# File 'lib/ios/sugarcube-attributedstring/nsattributedstring.rb', line 92 def letterpress with_attributes({ NSTextEffectAttributeName => NSTextEffectLetterpressStyle }) end |
#ligature(value) ⇒ Object
66 67 68 |
# File 'lib/cocoa/sugarcube-attributedstring/nsattributedstring.rb', line 66 def ligature(value) with_attributes({ NSLigatureAttributeName => value }) end |
#nsattributedstring(attributes = nil) ⇒ Object
96 97 98 99 100 101 102 |
# File 'lib/cocoa/sugarcube-attributedstring/nsattributedstring.rb', line 96 def nsattributedstring(attributes=nil) if attributes.nil? self else self.with_attributes(attributes) end end |
#paragraph_style(value) ⇒ Object
62 63 64 |
# File 'lib/cocoa/sugarcube-attributedstring/nsattributedstring.rb', line 62 def paragraph_style(value) with_attributes({ NSParagraphStyleAttributeName => value }) end |
#shadow(value) ⇒ Object
82 83 84 |
# File 'lib/cocoa/sugarcube-attributedstring/nsattributedstring.rb', line 82 def shadow(value) with_attributes({ NSShadowAttributeName => value }) end |
#strikethrough_style(value) ⇒ Object
78 79 80 |
# File 'lib/cocoa/sugarcube-attributedstring/nsattributedstring.rb', line 78 def strikethrough_style(value) with_attributes({ NSStrikethroughStyleAttributeName => value }) end |
#strip ⇒ Object
118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 |
# File 'lib/cocoa/sugarcube-attributedstring/nsattributedstring.rb', line 118 def strip # Trim leading whitespace and newlines. charSet = NSCharacterSet.whitespaceAndNewlineCharacterSet range = self.string.rangeOfCharacterFromSet(charSet) while (range.length != 0 && range.location == 0) self.replaceCharactersInRange(range, withString:"") range = self.string.rangeOfCharacterFromSet(charSet) end # Trim trailing whitespace and newlines. range = self.string.rangeOfCharacterFromSet(charSet, options:NSBackwardsSearch) while (range.length != 0 && NSMaxRange(range) == self.length) self.replaceCharactersInRange(range, withString:"") range = self.string.rangeOfCharacterFromSet(charSet, options:NSBackwardsSearch) end self end |
#stroke_color(value) ⇒ Object
79 80 81 |
# File 'lib/ios/sugarcube-attributedstring/nsattributedstring.rb', line 79 def stroke_color(value) with_attributes({ NSStrokeColorAttributeName => value.uicolor }) end |
#stroke_width(value) ⇒ Object
74 75 76 |
# File 'lib/cocoa/sugarcube-attributedstring/nsattributedstring.rb', line 74 def stroke_width(value) with_attributes({ NSStrokeWidthAttributeName => value }) end |
#subscript ⇒ Object
88 89 90 |
# File 'lib/ios/sugarcube-attributedstring/nsattributedstring.rb', line 88 def subscript superscript(-1) end |
#sugarcube_nsattributedstring_dummy_method ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/ios/sugarcube-attributedstring/nsattributedstring.rb', line 28 def sugarcube_nsattributedstring_dummy_method KCTCharacterShapeAttributeName KCTFontAttributeName KCTKernAttributeName KCTLigatureAttributeName KCTForegroundColorAttributeName KCTForegroundColorFromContextAttributeName KCTParagraphStyleAttributeName KCTStrokeWidthAttributeName KCTStrokeColorAttributeName KCTSuperscriptAttributeName KCTUnderlineColorAttributeName KCTUnderlineStyleAttributeName KCTVerticalFormsAttributeName KCTGlyphInfoAttributeName KCTRunDelegateAttributeName nil end |
#superscript(amount = nil) ⇒ Object
83 84 85 86 |
# File 'lib/ios/sugarcube-attributedstring/nsattributedstring.rb', line 83 def superscript(amount=nil) amount ||= 1 with_attributes({ KCTSuperscriptAttributeName => amount }) end |
#to_s ⇒ Object
58 59 60 |
# File 'lib/cocoa/sugarcube-attributedstring/nsattributedstring.rb', line 58 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 11 |
# File 'lib/ios/sugarcube-ui/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 label end end |
#underline ⇒ Object
61 62 63 |
# File 'lib/ios/sugarcube-attributedstring/nsattributedstring.rb', line 61 def underline underline_style(NSUnderlineStyleSingle) end |
#underline_style(value) ⇒ Object
65 66 67 |
# File 'lib/ios/sugarcube-attributedstring/nsattributedstring.rb', line 65 def underline_style(value) with_attributes({NSUnderlineStyleAttributeName => value}) end |
#vertical_glyph_form(value) ⇒ Object
86 87 88 |
# File 'lib/cocoa/sugarcube-attributedstring/nsattributedstring.rb', line 86 def vertical_glyph_form(value) with_attributes({ NSVerticalGlyphFormAttributeName => value }) end |
#with_attributes(attributes) ⇒ Object
90 91 92 93 94 |
# File 'lib/cocoa/sugarcube-attributedstring/nsattributedstring.rb', line 90 def with_attributes(attributes) retval = NSMutableAttributedString.alloc.initWithAttributedString(self) retval.addAttributes(attributes, range:[0, self.length]) retval end |