selectedRange for a UITextField?

Discussion in 'iOS Programming' started by ArtOfWarfare, Sep 5, 2011.

  1. ArtOfWarfare macrumors 604

    ArtOfWarfare

    Joined:
    Nov 26, 2007
    #1
    I know that you can get the selectedRange for a UITextView, but I was wondering if you could somehow do the same for a UITextField?
     
  2. jiminaus macrumors 65816

    jiminaus

    Joined:
    Dec 16, 2010
    Location:
    Sydney
    #2
    No. UITextField is for simple text entry. Remember that the ability to select text at all is a recent addition to iOS.

    In a UITextField, selecting text is just about editing that text. You'll need to use UITextView if you want the selecting of text to be more meaningful; that is, if you want to programmatically get that selection.
     
  3. ArtOfWarfare thread starter macrumors 604

    ArtOfWarfare

    Joined:
    Nov 26, 2007
    #3
    The workaround I'm using right now is I disabled my old UITextField, put a UITextView with the exact same frame on top of it, and set the backgroundColor property of UITextView to clearColor.

    Just curious, does anyone know a way I could make it so that all the text goes on one line in my UITextView rather than wrapping to another line?
     

Share This Page