0

I've read about this annoying bug on Stackoverflow, where if you don't make your UITextView selectable, setting the text will cause the font to reset, which is super annoying.

This seems to only work for when setting the normal text, not attributedText, because when I set attributedText it still resets the font, even if I have my the text view set to selectable.

This is really easy to replicate. Create a text view in a storyboard for instance (how I'm doing it), set a font, then set the attributed text to a plain string with myTextView.attributedText = NSAttributedString(string: "Lorem ipsum dolor.") and it gets reset.

How do I stop this? It's super annoying.

Community
  • 1
  • 1
Doug Smith
  • 29,668
  • 57
  • 204
  • 388
  • Since the font is included in the `NSAttributedString` (with `NSFontAttributedName`), I don't think it's a normal behavior, but at least, I'm not surprised. Maybe by iterating the previous `NSFontAttributedName` of `[myTextView attributedText]` and apply it to the `NSAttributedString`. – Larme Dec 16 '14 at 08:04

1 Answers1

0

I had the same issue and solved it with pragmatism as I'm sure it's a bug in iOS. So, my take might be not the best solution but one that'll work. Write a category for UITextView where with a method like -(void)setAttributedTextWithoutResettingFont:(NSAttributedString *)attributedText; and implement it such that your first save the current font in a temporary variable, then call the actual setter setAttributedText: on the UITextView and finally update the font again with the one saved in your temporary variable.

nburk
  • 22,409
  • 18
  • 87
  • 132