0

I have created a custom NSLayoutManager to render a border around certain characters in a string whenever a custom NSAttributedString attribute is found. The box is supposed to be bigger than the standard bounding box of the glyph which isn't hard to do. The problem I'm having is that if the glyph is on the edge of the text view, the sides are clipped. What I would like is for the box (or enough padding for the box) to be included in the layout calculations.

Here is an example of the box without proper padding:

String with improper padding

Here is an example of the box with proper padding:

String with proper padding

Sam Corder
  • 5,374
  • 3
  • 25
  • 30
  • Not sure of an answer here, but https://stackoverflow.com/questions/34504031/control-spacing-around-custom-text-attributes-in-nslayoutmanager poses a similar question. One of the answers there mentions using custom control characters and setting their width, which for me wasn't an ideal solution for me since when editable, the text view's cursor selects and steps over the control characters. If you've figured out a way to implement this, would love to hear it! – Noah Gilmore Feb 19 '20 at 07:21
  • 1
    iOS text views don’t give the level of control over text layout that macOS does. I ended up rendering the text with boxes and other shapes into an image that I attached to the attributed string. It works for my situation but isn’t ideal for longer text spans. The images also need to be rerendered when switching to/from dark mode. – Sam Corder Feb 20 '20 at 13:20

0 Answers0