Class: NSMutableAttributedString

Inherits:
Object
  • Object
show all
Defined in:
lib/hotcocoa/core_extensions/nsmutable_attributed_string.rb

Overview

HotCocoa extensions to the NSMutableAttributeString class.

Instance Method Summary collapse

Instance Method Details

#+(s) ⇒ Object

TODO:

Should this be declared on NSAttributedString instead

Just like String#+



32
33
34
35
36
# File 'lib/hotcocoa/core_extensions/nsmutable_attributed_string.rb', line 32

def + s
  attributed_string = mutableCopy
  attributed_string << s
  attributed_string
end

#<<(s) ⇒ Object

Just like String#<<



19
20
21
22
23
24
25
26
# File 'lib/hotcocoa/core_extensions/nsmutable_attributed_string.rb', line 19

def << s
  case s
  when String
    mutableString.appendString s
  else
    appendAttributedString s
  end
end

#[](r) ⇒ HotCocoa::NSRangedProxyAttributedString

Deprecated.

Who uses this? Removing this in HotCocoa 0.7 unless there are reasonable objections

Create a range proxy for an arbitrary portion of the receiver.

Parameters:

Returns:



56
57
58
# File 'lib/hotcocoa/core_extensions/nsmutable_attributed_string.rb', line 56

def [] r
  HotCocoa::NSRangedProxyAttributedString.new self, r
end

#[]=(r, s) ⇒ Object

Replace an arbitrary range of an attributed string with another string.

Parameters:

  • r (Range)
  • s (NSAttributedString, String)


65
66
67
68
69
70
71
72
# File 'lib/hotcocoa/core_extensions/nsmutable_attributed_string.rb', line 65

def []= r, s
  case s
  when String
    replaceCharactersInRange r.to_NSRange(length), withString: s
  else
    replaceCharactersInRange r.to_NSRange(length), withAttributedString: s
  end
end

#attributesHotCocoa::NSRangedProxyAttributeHash

TODO:

Should this be declared on NSAttributedString instead

Hash of attributes used in the attributed string.



44
45
46
# File 'lib/hotcocoa/core_extensions/nsmutable_attributed_string.rb', line 44

def attributes
  HotCocoa::NSRangedProxyAttributedString.new(self, 0..-1).attributes
end

#with_attributes(attributes = {}) ⇒ NSMutableAttributedString

TODO:

Should this be declared on NSAttributedString instead

Make a new attributed string with the string of the receiver and the attributes passed as arguments.

Parameters:

  • (Hash)

Returns:



13
14
15
# File 'lib/hotcocoa/core_extensions/nsmutable_attributed_string.rb', line 13

def with_attributes attributes = {}
  string.with_attributes attributes
end