Search code examples
htmlcocoaosx-lionseparatornsattributedstring

Horizontal <hr>-like separator in NSAttributedString


How can I make a NSAttributedString that would basically be a horizontal separator, like HTML's <hr> tag?

I've tried:

NSAttributedString *hr = [[NSAttributedString alloc] initWithHTML:
  [NSData
    dataWithBytes:"<html><body><hr>hi</body></html>"
    length:strlen("<html><body><hr>hi</body></html>")]
  documentAttributes:NULL];

However, the <hr> tag doesn't appear. Adding the string to my view works though, because I can see the hi.


Solution

  • You're going to have to draw it yourself. <hr> is not text, or an attribute that modifies text. Therefore, NSAttributedString cannot represent it and the Cocoa text system or CoreText has no facility to draw it.