1

How do I determine the current state of the UIResponderStandardEditActions for text formatting? For example, if I do the following:

[textView toggleBoldface:nil];

How do I query the textView to find out if the state of bold is now on or off? This is for just a cursor with no selection (i.e. range length is 0). As such, enumerateAttribute doesn't seem to work.

Thank you.

ajfigueroa
  • 597
  • 7
  • 16
DenVog
  • 4,226
  • 3
  • 43
  • 72

2 Answers2

1

It appears the typingAttributes property (available in iOS 6) will log the attributes that will be applied to new text typed by the user, even with a selection length of 0. Thus revealing what the state of formatting options such as bold will be.

NSLog(@"textViewFormatting options: %@", [[self noteTextView] typingAttributes]);
DenVog
  • 4,226
  • 3
  • 43
  • 72
0

I'm not finding anything useful in the docs, but I suppose it would be simple enough to just subclass UITextView, add a property on it like BOOL boldText and then wherever you call [textView toggleBoldFace:nil]; just toggle that property as well. And then when you need to check the state of the textView, just check the boldText property instead.

geraldWilliam
  • 4,123
  • 1
  • 23
  • 35
  • Hi Gerald. I appreciate the suggestion, but I don't think it will work for a couple reasons. The main being that while bold is a BOOL, the state you expect to see can change without a toggle event (i.e. move the cursor). For example I may have 3 bold words. Putting the cursor between letters of any of those word should return a bold state. If I put the cursor between letters in a 4th word that is not bold, it should not return a bold state. So here, there is not a toggle event to change state. Just placing the cursor somewhere different should return a different result. Hope that makes sense. – DenVog Oct 24 '12 at 01:21
  • I did not realize that you would be changing the state via anything but toggle. I'll come back to this if I think of something useful. – geraldWilliam Oct 24 '12 at 17:32