Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6057469
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T08:29:31+00:00 2026-05-23T08:29:31+00:00

I need to tweak UiTextField behavior so that I can programmatically insert some asterisks

  • 0

I need to tweak UiTextField behavior so that I can programmatically insert some asterisks and move the cursor at the beginning of the string;
I tried the “paste” trick (http://dev.ragfield.com/2009/09/insert-text-at-current-cursor-location.html), but the cursor is moved at the end.
The effect I try to achieve is like this:
At the start:


then the user insert characters
f*****
fo****
foo***
etc…

Is this possible or the tweaks I’ve to do don’t deserve the effort?

Thanx

-G-

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T08:29:32+00:00Added an answer on May 23, 2026 at 8:29 am

    UPDATE:

    In iOS5 and above is possible to do this because UITextField and UITextView conform to UITextInput protocol. Please take a look at this: ” Can I select a specific block of text in a UITextField? ” for an example :).

    Hope it helps


    OLD ANSWER: (iOS4.x and below):

    There is no way to accomplish this using public APIs (Not that I know).
    However I have found a couple of private methods: (maybe undocumented methods because they don’t have the underscore prefix that private methods usually have)

    selectionRange
    setSelectionRange:
    

    Below code work fine (at least in the simulator 4.3) and I am using KVC so I can avoid annoying warnings. (self is a instance of a subclass of UITextField)

    - (void) moveToRight{
    
        NSRange selectedRange = [[self valueForKey:@"selectionRange"] rangeValue];
        if (selectedRange.location != NSNotFound) {
            if (selectedRange.length > 0) {
                selectedRange.location = NSMaxRange(selectedRange);
                selectedRange.length = 0;
            }else if (selectedRange.location < self.text.length) {
                selectedRange.location += 1;
            }
            [self setValue:[NSValue valueWithRange:selectedRange] forKey:@"selectionRange"];
        }
    }
    - (void) moveToLeft{
    
        NSRange selectedRange = [[self valueForKey:@"selectionRange"] rangeValue];
        if (selectedRange.location != NSNotFound) {
            if (selectedRange.length > 0) {
                selectedRange.length = 0;
            }else if (selectedRange.location > 0) {
                selectedRange.location -= 1;
            }
            [self setValue:[NSValue valueWithRange:selectedRange] forKey:@"selectionRange"];
        }
    }
    

    Since these are not public APIs, use at your own risk, I don’t know if they will pass Apple’s review.

    BTW:
    I found them using:

    #import "/usr/include/objc/objc-runtime.h"
    
    unsigned int methodCount = 0;
    Method *mlist = class_copyMethodList([UITextField class], &methodCount);
    for (int i = 0; i < methodCount; ++i){
        NSLog(@"%@", NSStringFromSelector(method_getName(mlist[i])));
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to tweak some variables (only in a development setting) without having to
I need to tweak some things inside Tomcat 6.0 before any web applications or
Need a function that takes a character as a parameter and returns true if
Need to an expression that returns only things with an I followed by either
need ask you about some help. I have web app running in Net 2.0.
Need a function like: function isGoogleURL(url) { ... } that returns true iff URL
I need to tweak the web interface of an in-house print system, but it's
I have an AS class with setter and getter functions. I need to tweak
I need to solve the following question which i can't get to work by
i have a input tag which is non editable, but some times i need

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.