Domanda

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.

È stato utile?

Soluzione

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]);

Altri suggerimenti

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.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top