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 8370429
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T13:54:35+00:00 2026-06-09T13:54:35+00:00

I would like a text similar to Twitter’s I am currently using a UITextView

  • 0

I would like a text similar to Twitter’s

I am currently using a UITextView since it has multi-line support. I kind of figured out how to use a label that counts the characters and keeps the user up to date of any characters added or removed.

Empty:

Empty Field

With Text:

With Text

The problem I am having however is when I copy or paste any text in the view, (like if I highlight all the text, as in the second picture) and I delete it, the counter will not update. Or if I paste any text, the count just decrements one character, though the text field limit still stays correct, just the counter is no longer in sync with it.

Code: http://pastebin.com/UK91Ccbb

  • 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-06-09T13:54:37+00:00Added an answer on June 9, 2026 at 1:54 pm

    There is a delegate method for UITextView as

    - (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text;
    

    it is called every time a character is inserted into the UITextView. In this method set the length of text in your counter UILabel as follows

    counterlabel.text = [NSString stringWithFormat:@"%i", textView.text.length];
    

    return YES at the end of method if the length is within range i.e. less than or equal to 140 else return NO.

    UPDATE:..
    To restrict to 140 characters.

    - (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text
    {
        return textView.text.length <= 140;
    
    }
    

    To handle text removal on selection and counting characters.

    - (void)textViewDidChange:(UITextView *)textView
    {
        count.text = [NSString stringWithFormat:@"%i", (140- textView.text.length)];
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like to truncate a text or line with DOTS using JavaScript but
I would like to draw text on a canvas using the Canvas.drawText call for
I would like to give text shadow for my text using css3. Can anyone
I recently started using Masterpages, the thing is I would like to add text
I am designing a text based game similar to Zork, and I would like
I would like to create a similar system to the facebook status update using
I would like to create a UITableViewCell that has a similar style a the
I am using Jeff Sharkey's SeparatedListAdapter and I would like to set the text
I would like the text in the value field of a text box to
I would like my text entry to round off decimals and have the end

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.