class NSAttributedString

Public Instance Methods

+(attributedstring) click to toggle source
# 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) click to toggle source
# File lib/cocoa/sugarcube-attributedstring/nsattributedstring.rb, line 104
def attrd(attributes=nil)
  self.nsattributedstring(attributes=nil)
end
background_color(value) click to toggle source
# File lib/ios/sugarcube-attributedstring/nsattributedstring.rb, line 84
def background_color(value)
  value = value.uicolor if value.respond_to?(:uicolor)
  with_attributes({ NSBackgroundColorAttributeName => value })
end
Also aliased as: bg_color, bg_color
bg_color(value)
Alias for: background_color
bold(size=nil) click to toggle source
# File lib/ios/sugarcube-attributedstring/nsattributedstring.rb, line 47
def bold(size=nil)
  size ||= UIFont.systemFontSize
  font = UIFont.boldSystemFontOfSize(size)
  self.font(font)
end
color(value)
Alias for: foreground_color
empty?() click to toggle source
# File lib/cocoa/sugarcube-attributedstring/nsattributedstring.rb, line 114
def empty?
  self.length == 0
end
font(value) click to toggle source
# File lib/ios/sugarcube-attributedstring/nsattributedstring.rb, line 65
def font(value)
  value = value.uifont if value.respond_to?(:uifont)
  with_attributes({ NSFontAttributeName => value })
end
foreground_color(value) click to toggle source
# File lib/ios/sugarcube-attributedstring/nsattributedstring.rb, line 78
def foreground_color(value)
  value = value.uicolor if value.respond_to?(:uicolor)
  with_attributes({ NSForegroundColorAttributeName => value })
end
Also aliased as: color, color
italic(size=nil) click to toggle source
# File lib/ios/sugarcube-attributedstring/nsattributedstring.rb, line 53
def italic(size=nil)
  size ||= UIFont.systemFontSize
  font = UIFont.italicSystemFontOfSize(size)
  self.font(font)
end
kern(value) click to toggle source
# File lib/cocoa/sugarcube-attributedstring/nsattributedstring.rb, line 70
def kern(value)
  with_attributes({ NSKernAttributeName => value })
end
letterpress() click to toggle source
# File lib/ios/sugarcube-attributedstring/nsattributedstring.rb, line 104
def letterpress
  with_attributes({ NSTextEffectAttributeName => NSTextEffectLetterpressStyle })
end
ligature(value) click to toggle source
# File lib/cocoa/sugarcube-attributedstring/nsattributedstring.rb, line 66
def ligature(value)
  with_attributes({ NSLigatureAttributeName => value })
end
monospace(size=nil) click to toggle source
# File lib/ios/sugarcube-attributedstring/nsattributedstring.rb, line 59
def monospace(size=nil)
  size ||= UIFont.systemFontSize
  font = UIFont.fontWithName('Courier New', size: size)
  self.font(font)
end
nsattributedstring(attributes=nil) click to toggle source
# 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) click to toggle source
# File lib/cocoa/sugarcube-attributedstring/nsattributedstring.rb, line 62
def paragraph_style(value)
  with_attributes({ NSParagraphStyleAttributeName => value })
end
shadow(value) click to toggle source
# File lib/cocoa/sugarcube-attributedstring/nsattributedstring.rb, line 82
def shadow(value)
  with_attributes({ NSShadowAttributeName => value })
end
strikethrough_style(value) click to toggle source
# File lib/cocoa/sugarcube-attributedstring/nsattributedstring.rb, line 78
def strikethrough_style(value)
  with_attributes({ NSStrikethroughStyleAttributeName => value })
end
strip() click to toggle source
# 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) click to toggle source
# File lib/ios/sugarcube-attributedstring/nsattributedstring.rb, line 90
def stroke_color(value)
  value = value.uicolor if value.respond_to?(:uicolor)
  with_attributes({ NSStrokeColorAttributeName => value })
end
stroke_width(value) click to toggle source
# File lib/cocoa/sugarcube-attributedstring/nsattributedstring.rb, line 74
def stroke_width(value)
  with_attributes({ NSStrokeWidthAttributeName => value })
end
subscript() click to toggle source
# File lib/ios/sugarcube-attributedstring/nsattributedstring.rb, line 100
def subscript
  superscript(-1)
end
sugarcube_nsattributedstring_dummy_method() click to toggle source
# File lib/cocoa/sugarcube-attributedstring/nsattributedstring.rb, line 30
def sugarcube_nsattributedstring_dummy_method
  # make sure NSAttributedString constants get compiled
  NSFontAttributeName
  NSParagraphStyleAttributeName
  NSForegroundColorAttributeName
  NSBackgroundColorAttributeName
  NSLigatureAttributeName
  NSKernAttributeName
  NSStrikethroughStyleAttributeName
  NSUnderlineStyleAttributeName
  NSStrokeColorAttributeName
  NSStrokeWidthAttributeName
  NSShadowAttributeName
  NSVerticalGlyphFormAttributeName
  # new iOS 7 text effects
  NSTextEffectAttributeName
  NSTextEffectLetterpressStyle
  NSRTFDTextDocumentType
  NSHTMLTextDocumentType
  # make sure alignments get compiled
  NSLeftTextAlignment
  NSRightTextAlignment
  NSCenterTextAlignment
  NSJustifiedTextAlignment
  NSNaturalTextAlignment
  nil
end
superscript(amount=nil) click to toggle source
# File lib/ios/sugarcube-attributedstring/nsattributedstring.rb, line 95
def superscript(amount=nil)
  amount ||= 1
  with_attributes({ KCTSuperscriptAttributeName => amount })
end
to_s() click to toggle source
# 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() click to toggle source

@return [UILabel]

# 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() click to toggle source
# File lib/ios/sugarcube-attributedstring/nsattributedstring.rb, line 70
def underline
  underline_style(NSUnderlineStyleSingle)
end
underline_style(value) click to toggle source
# File lib/ios/sugarcube-attributedstring/nsattributedstring.rb, line 74
def underline_style(value)
  with_attributes({NSUnderlineStyleAttributeName => value})
end
vertical_glyph_form(value) click to toggle source
# File lib/cocoa/sugarcube-attributedstring/nsattributedstring.rb, line 86
def vertical_glyph_form(value)
  with_attributes({ NSVerticalGlyphFormAttributeName => value })
end
with_attributes(attributes) click to toggle source
# 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