Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Extract first word from UITextView

In my app I have a UILabel which is the title and a UITextView which is the description and I want the title UILabel to be the first word typed into the UITextView. Does anyone know how to do this?

like image 935
timothy5216 Avatar asked Mar 08 '26 00:03

timothy5216


1 Answers

If I understand well your problem, this code might do the trick:

- (void)textViewDidChange:(UITextView *)textView
{
    NSString *text = _textView.text;
    NSArray *elements = [text componentsSeparatedByString:@" "];
    if ([elements count] > 0)
    {
        _label.text = [elements objectAtIndex:0];
    }
}
like image 82
Adrian Kosmaczewski Avatar answered Mar 09 '26 13:03

Adrian Kosmaczewski