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

  • SEARCH
  • Home
  • 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 7558553
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T12:23:59+00:00 2026-05-30T12:23:59+00:00

I have a UITextView and need to make a specific portion un-deletable. Its the

  • 0

I have a UITextView and need to make a specific portion un-deletable. Its the first 10 characters of the views text.

I just want it so that if the user is tapping the delete key on the keyboard it simply stops when it reaches say the 10th character in.

Edit

Let me go into a bit more detail.

Let’s say the prefix is ‘123456789:’. I want to be able to type anywhere after this prefix, it can’t be editable at all though, so ‘123456789:’ shouldn’t not be altered at all. Fichek’s answer does this perfectly, however the prefix isn’t always there, so how can I detect when it isn’t in the textview? I thought the if statement did this but it seems not to.

  • 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-30T12:24:00+00:00Added an answer on May 30, 2026 at 12:24 pm

    sch’s last edit makes a decent answer, but I want to offer a slightly more flexible approach.

    You have to keep in mind the copy/paste system. User might select all the text in text field and try to paste in the entire value which might be perfectly acceptable, but if (range.location <= 9) { return NO; } will reject it. The way I’d do it is put together a string that would be a result of successful edit and then check if that string would start with your desired prefix.

    - (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string
    {
        NSString *resultString = [textField.text stringByReplacingCharactersInRange:range withString:string];
        NSLog(@"resulting string would be: %@", resultString);
        NSString *prefixString = @"blabla";
        NSRange prefixStringRange = [resultString rangeOfString:prefixString];
        if (prefixStringRange.location == 0) {
            // prefix found at the beginning of result string
            return YES;
        }
        return NO;
    }
    

    Edit: if you want to check if the current string in text field starts with the prefix, you can use rangeOfString: the same way:

    NSRange prefixRange = [textField.text rangeOfString:prefixString];
    if (prefixRange.location == 0) {
        // prefix found at the beginning of text field
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some text in a UITextView, that I would like to have show
I have a large amount of text in a UITextView. I want to let
I have a UITextView that is supposed to have one line of text. The
I have a need to display text that includes HTML tags etc and TTStyledTextLabel
I have an UITextView which is for instance 380 characters in length: NSLog(@aTextView.text lenght
I have UITextView and I want to use scroll bar when text is longer
I have a UITextView that has a lot of content. I have a button
Setup: I have a UITextView inside a UITableViewCell 's contentView . I want it
I'm writing iPhone/iPad application. I have UITextView in which I automatically appending text. How
I have a UITextView subclass that has an NSIndexPath property that is inside a

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.