The question is ahead:
Is it possible to directly access font and font information for an attribute string? Or can we create a new line for which we can set this information?
Explanation:
In iOS 6, you can select the selection in bold or italics. But the way it works is annoying: it does not change the name NSFontAttributeName that Apple set for us (changing the font name, for example, "HelveticaNeue" to "HelveticaNeue-Bold"). Instead, it saves the font family as "Helvetica Neue" and changes the "font-weight" to bold in the style bar. If you want to ask an instance of attribute text for its description, you will see something like this for font information:
NSFont = "<UICFFont: 0x1fbc53a0> font-family: \"Helvetica Neue\"; font-weight: bold; font-style: normal; font-size: 16px";
This creates a problem. We cannot change the font while maintaining a bold and italic style. If you go through the scan hoops of the old attribute string for style information, create a new string with a new font and then change the font attribute name (using, for example, “Courier-Bold” wherever you want it to be in bold), you are creating a new problem: if you try to switch the font back to normal (not bold), instead you will get a font name, such as “Courier-Bold” and a font “bold”, because the style information has not yet been bold. And switching, of course, will not change the font name. Thus, you essentially created a font that can no longer be changed when the user switches the selected text. The user will press the “bold” button in the context menu, but will do nothing, because courage was now rigidly indicated in the font name, you could say.
If you switch to a different route and try to override "toggleBoldface" and "toggleItalic" in your UITextView, it is not possible to actually prohibit changing the style information in the style line. You cannot apparently change the font name only during a switch event.
So, again, the question is: is it possible to somehow immediately get access to information about the font and the font? Or can we create a new line for which we can set this information? This will solve the problem of trying to switch from one font to another and save style information.
And a double clarification:
We are talking about iOS. When you set an attribute of an attribute with an attribute string (NSFontAttributeName) for a range of characters, internally iOS creates an NSFont with a style string. The style line will read "font-weight: normal; font-style: normal" if you set the font attribute yourself. But this style line is where the bold and italic information set in the UITextView (by switching) is stored.