Extract first word from UITextView

In my application, I have UILabel, which is the title, and UITextView, which is the description, and I want the name UILabel to be the first word entered in the UITextView. Does anyone know how to do this?

+3
source share
1 answer

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

- (void)textViewDidChange:(UITextView *)textView
{
    NSString *text = _textView.text;
    NSArray *elements = [text componentsSeparatedByString:@" "];
    if ([elements count] > 0)
    {
        _label.text = [elements objectAtIndex:0];
    }
}
+2
source

Source: https://habr.com/ru/post/1727166/


All Articles