Cory Rylan

My name is , Google Developer Expert, Speaker, Software Developer. Building Design Systems and Web Components.

Follow @coryrylan
Cory Rylan Blog

IOS Character Counter

Cory Rylan

-

This following example is a small character counter that can keep track of the number of characters in a text view that needs to be limited to a maximum amount of characters.

//Only check if text field has been altered
-(void)textViewDidChange:(UITextView *)textView{
    //500 chars max
    if([[textView text] length] > 500){
        //If max reached close keypad
        [textView resignFirstResponder];
        //Append off extra chars
        textView.text = [textView.text substringToIndex:500];
    }
    //Count and display amount of chars left
    CounterBoxLabel.text = [NSString stringWithFormat:@"Characters left: (%i)", 500 - [[textView text] length]];
}
Twitter Facebook LinkedIn Email
 

No spam. Short occasional updates on Web Development articles, videos, and new courses in your inbox.

Related Posts

Cory Rylan Blog

IOS Journey the Observer

A short code example of how to use the observer object for IOS in Objective C.

Read Article
Cory Rylan Blog

IOS Journey Load Multi-Threading

A short code example of how to use multi-threading for IOS in Objective C.

Read Article
Cory Rylan Blog

IOS Journey Load Animation

A short code example of how to create a load animation for IOS in Objective C.

Read Article