I've been doing it using selectedTextRange and beginningOfDocument properties from the UITextInput protocol, but as I just learned in the post below, UITextField only starts adhering to the UITextInput protocol in iOS 5, so my app is crashing in iOS 4.3. I need another way to do this in iOS 4.3.
UITextInput protocol usage for UITextField and UITextView to manage selection results in crash.
Here's what I'm doing now (self is my UITextField subclass):
UITextRange *selectedTextRange = self.selectedTextRange;
NSUInteger location = [self offsetFromPosition:self.beginningOfDocument
toPosition:selectedTextRange.start];
NSUInteger length = [self offsetFromPosition:selectedTextRange.start
toPosition:selectedTextRange.end];
NSRange selectedRange = NSMakeRange(location, length);