Class: NSAttributedString

Inherits:
Object show all
Defined in:
lib/sugarcube-attributedstring/nsattributedstring.rb

Constant Summary collapse

NSSuperscriptAttributeName =
'NSSuperscript'
NSAttachmentAttributeName =
'NSAttachment'
NSBaselineOffsetAttributeName =
'NSBaselineOffset'
NSLinkAttributeName =
'NSLink'
NSUnderlineColorAttributeName =
'NSUnderlineColor'
NSStrikethroughColorAttributeName =
'NSStrikethroughColor'
NSObliquenessAttributeName =
'NSObliqueness'
NSExpansionAttributeName =
'NSExpansion'
NSCursorAttributeName =
'NSCursor'
NSToolTipAttributeName =
'NSToolTip'
NSMarkedClauseSegmentAttributeName =
'NSMarkedClauseSegment'
NSWritingDirectionAttributeName =
'NSWritingDirection'
NSTextAlternativesAttributeName =
'NSTextAlternatives'

Instance Method Summary collapse

Instance Method Details

#+(attributedstring) ⇒ Object



228
229
230
# File 'lib/sugarcube-attributedstring/nsattributedstring.rb', line 228

def +(attributedstring)
  NSMutableAttributedString.alloc.initWithAttributedString(self) + attributedstring
end

#attachment(value) ⇒ Object



142
143
144
# File 'lib/sugarcube-attributedstring/nsattributedstring.rb', line 142

def attachment(value)
  with_attributes({NSAttachmentAttributeName => value})
end

#background_color(value) ⇒ Object Also known as: bg_color



137
138
139
# File 'lib/sugarcube-attributedstring/nsattributedstring.rb', line 137

def background_color(value)
  with_attributes({NSBackgroundColorAttributeName => value})
end

#baseline_offset(value) ⇒ Object



150
151
152
# File 'lib/sugarcube-attributedstring/nsattributedstring.rb', line 150

def baseline_offset(value)
  with_attributes({NSBaselineOffsetAttributeName => value})
end

#bold(size = nil) ⇒ Object



92
93
94
95
# File 'lib/sugarcube-attributedstring/nsattributedstring.rb', line 92

def bold(size=nil)
  font = :bold.uifont(size)
  self.font(font)
end

#cursor(value) ⇒ Object



194
195
196
# File 'lib/sugarcube-attributedstring/nsattributedstring.rb', line 194

def cursor(value)
  with_attributes({NSCursorAttributeName => value})
end

#dummyObject



55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/sugarcube-attributedstring/nsattributedstring.rb', line 55

def dummy
  foo = NSFontAttributeName
  foo = NSParagraphStyleAttributeName
  foo = NSForegroundColorAttributeName
  foo = NSUnderlineStyleAttributeName
  foo = NSSuperscriptAttributeName
  foo = NSBackgroundColorAttributeName
  foo = NSAttachmentAttributeName
  foo = NSLigatureAttributeName
  foo = NSBaselineOffsetAttributeName
  foo = NSKernAttributeName
  foo = NSLinkAttributeName
  foo = NSStrokeWidthAttributeName
  foo = NSStrokeColorAttributeName
  foo = NSUnderlineColorAttributeName
  foo = NSStrikethroughStyleAttributeName
  foo = NSStrikethroughColorAttributeName
  foo = NSShadowAttributeName
  foo = NSObliquenessAttributeName
  foo = NSExpansionAttributeName
  foo = NSCursorAttributeName
  foo = NSToolTipAttributeName
  foo = NSMarkedClauseSegmentAttributeName
  foo = NSWritingDirectionAttributeName
  foo = NSVerticalGlyphFormAttributeName
  foo = NSTextAlternativesAttributeName
  foo = NSLeftTextAlignment
  foo = NSRightTextAlignment
  foo = NSCenterTextAlignment
  foo = NSJustifiedTextAlignment
  foo = NSNaturalTextAlignment
end

#expansion(value) ⇒ Object



190
191
192
# File 'lib/sugarcube-attributedstring/nsattributedstring.rb', line 190

def expansion(value)
  with_attributes({NSExpansionAttributeName => value})
end

#font(value) ⇒ Object



116
117
118
# File 'lib/sugarcube-attributedstring/nsattributedstring.rb', line 116

def font(value)
  with_attributes({NSFontAttributeName => value.uifont})
end

#foreground_color(value) ⇒ Object Also known as: color



124
125
126
# File 'lib/sugarcube-attributedstring/nsattributedstring.rb', line 124

def foreground_color(value)
  with_attributes({NSForegroundColorAttributeName => value})
end

#italic(size = nil) ⇒ Object



97
98
99
100
# File 'lib/sugarcube-attributedstring/nsattributedstring.rb', line 97

def italic(size=nil)
  font = :italic.uifont(size)
  self.font(font)
end

#kern(value) ⇒ Object



154
155
156
# File 'lib/sugarcube-attributedstring/nsattributedstring.rb', line 154

def kern(value)
  with_attributes({NSKernAttributeName => value})
end

#ligature(value) ⇒ Object



146
147
148
# File 'lib/sugarcube-attributedstring/nsattributedstring.rb', line 146

def ligature(value)
  with_attributes({NSLigatureAttributeName => value})
end


158
159
160
# File 'lib/sugarcube-attributedstring/nsattributedstring.rb', line 158

def link(value)
  with_attributes({NSLinkAttributeName => value})
end

#marked_clause_segment(value) ⇒ Object



202
203
204
# File 'lib/sugarcube-attributedstring/nsattributedstring.rb', line 202

def marked_clause_segment(value)
  with_attributes({NSMarkedClauseSegmentAttributeName => value})
end

#nsattributedstringObject



224
225
226
# File 'lib/sugarcube-attributedstring/nsattributedstring.rb', line 224

def nsattributedstring
  self
end

#obliqueness(value) ⇒ Object



186
187
188
# File 'lib/sugarcube-attributedstring/nsattributedstring.rb', line 186

def obliqueness(value)
  with_attributes({NSObliquenessAttributeName => value})
end

#paragraph_style(value) ⇒ Object



120
121
122
# File 'lib/sugarcube-attributedstring/nsattributedstring.rb', line 120

def paragraph_style(value)
  with_attributes({NSParagraphStyleAttributeName => value})
end

#shadow(value) ⇒ Object



182
183
184
# File 'lib/sugarcube-attributedstring/nsattributedstring.rb', line 182

def shadow(value)
  with_attributes({NSShadowAttributeName => value})
end

#strikethrough_color(value) ⇒ Object



178
179
180
# File 'lib/sugarcube-attributedstring/nsattributedstring.rb', line 178

def strikethrough_color(value)
  with_attributes({NSStrikethroughColorAttributeName => value})
end

#strikethrough_style(value) ⇒ Object



174
175
176
# File 'lib/sugarcube-attributedstring/nsattributedstring.rb', line 174

def strikethrough_style(value)
  with_attributes({NSStrikethroughStyleAttributeName => value})
end

#stroke_color(value) ⇒ Object



166
167
168
# File 'lib/sugarcube-attributedstring/nsattributedstring.rb', line 166

def stroke_color(value)
  with_attributes({NSStrokeColorAttributeName => value})
end

#stroke_width(value) ⇒ Object



162
163
164
# File 'lib/sugarcube-attributedstring/nsattributedstring.rb', line 162

def stroke_width(value)
  with_attributes({NSStrokeWidthAttributeName => value})
end

#superscript(value) ⇒ Object



133
134
135
# File 'lib/sugarcube-attributedstring/nsattributedstring.rb', line 133

def superscript(value)
  with_attributes({NSSuperscriptAttributeName => value})
end

#text_alternatives(value) ⇒ Object



214
215
216
# File 'lib/sugarcube-attributedstring/nsattributedstring.rb', line 214

def text_alternatives(value)
  with_attributes({NSTextAlternativesAttributeName => value})
end

#to_sObject



88
89
90
# File 'lib/sugarcube-attributedstring/nsattributedstring.rb', line 88

def to_s
  string
end

#tool_tip(value) ⇒ Object



198
199
200
# File 'lib/sugarcube-attributedstring/nsattributedstring.rb', line 198

def tool_tip(value)
  with_attributes({NSToolTipAttributeName => value})
end

#uilabelUILabel

Parameters:

  • font (UIFont)

    Optional, defaults to UIFont.systemFontOfSize(UIFont.systemFontSize)

Returns:



108
109
110
111
112
113
114
# File 'lib/sugarcube-attributedstring/nsattributedstring.rb', line 108

def uilabel
  UILabel.alloc.initWithFrame([[0, 0], [0, 0]]).tap { |label|
    label.attributedText = self
    label.backgroundColor = :clear.uicolor
    label.sizeToFit
  }
end

#underlineObject



102
103
104
# File 'lib/sugarcube-attributedstring/nsattributedstring.rb', line 102

def underline
  underline_style(NSUnderlineStyleSingle)
end

#underline_color(value) ⇒ Object



170
171
172
# File 'lib/sugarcube-attributedstring/nsattributedstring.rb', line 170

def underline_color(value)
  with_attributes({NSUnderlineColorAttributeName => value})
end

#underline_style(value) ⇒ Object



129
130
131
# File 'lib/sugarcube-attributedstring/nsattributedstring.rb', line 129

def underline_style(value)
  with_attributes({NSUnderlineStyleAttributeName => value})
end

#vertical_glyph_form(value) ⇒ Object



210
211
212
# File 'lib/sugarcube-attributedstring/nsattributedstring.rb', line 210

def vertical_glyph_form(value)
  with_attributes({NSVerticalGlyphFormAttributeName => value})
end

#with_attributes(attributes) ⇒ Object



218
219
220
221
222
# File 'lib/sugarcube-attributedstring/nsattributedstring.rb', line 218

def with_attributes(attributes)
  retval = NSMutableAttributedString.alloc.initWithAttributedString(self)
  retval.addAttributes(attributes, range:[0, self.length])
  retval
end

#writing_direction(value) ⇒ Object



206
207
208
# File 'lib/sugarcube-attributedstring/nsattributedstring.rb', line 206

def writing_direction(value)
  with_attributes({NSWritingDirectionAttributeName => value})
end