开发者

Extract first word from UITextView

开发者 https://www.devze.com 2022-12-15 20:37 出处:网络
In my app I have a UILabel which is the title and a UITextView which is the description and I want the title UILabel t开发者_运维知识库o be the first word typed into the UITextView. Does anyone know h

In my app I have a UILabel which is the title and a UITextView which is the description and I want the title UILabel t开发者_运维知识库o be the first word typed into the UITextView. Does anyone know how to do this?


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];
    }
}
0

精彩评论

暂无评论...
验证码 换一张
取 消