2

I have a UITextView and I automatically write the date in it. I would then like to have the cursor after the date, with the shift (capitalize) button pressed so the user can just start typing and the first letter will be capitalized.

Is this possible? How can I do this?

Appreciate the help! Thanks, R

Rossi
  • 609
  • 6
  • 14
  • 2
    Curious - have you tried setting the text such that it ends with a period and a space, then putting the cursor at the end? Does this automatically turn on the shift key? Is the text view setup to capitalize sentences? – rmaddy Oct 21 '12 at 23:25
  • Yeah that would work. I just don't want to have a period there. But that would work. – Rossi Oct 21 '12 at 23:41

2 Answers2

1

For multi-language support and ensuring that you don't miss any use cases, you may want to use a technique that allows you to defer to the keyboard's built-in functionality.

You can do this by temporarily setting autocapitalizationType to .allCharacters (optionally in a subclass):

if (autocapitalizationType == .allCharacters) {
    autocapitalizationType = .sentences
    autocorrectionType = .yes
    reloadInputViews()
}

Take a look at his post.

Sheamus
  • 6,506
  • 3
  • 35
  • 61
0

Just convert the ascii value automatically instead.

http://www.asciitable.com/

I think you have to subtract 32 to get from 'a' to 'A'.

Xathereal
  • 367
  • 1
  • 7
  • 1
    I think you misunderstand what is being asked. – rmaddy Oct 21 '12 at 23:25
  • No, that makes sense - I'll give that a shot – Rossi Oct 21 '12 at 23:42
  • @Rossi - can you explain how this is related to your question? Also, this won't work for any letters other than a-z. You have an international audience that will be using many other letters. If you need to change the case of a string, use the **NSString** method `lowercaseString`. – rmaddy Oct 21 '12 at 23:44
  • Related because I could autocorrect it to be capital after they wrote it, using the ascii value. However, you are correct about only working for a-z. So I will try to use the same concept but with uppercaseString instead - hopefully that works across the board. Was still hoping there was some method: selectShiftKey hidden somewhere but alas, I don't think there is. – Rossi Oct 21 '12 at 23:48