How to make #key and @key clickable in iOS7

Does anyone know how I can make #KEY and @NAME available in comment text in iOS7 (just like Instagram does)? I'm trying to use NSMutableAttributedString, but I'm not sure how to detect a click event in the image below, by clicking @Username, I must enter the user in the user profile.

enter image description here

+4
source share
3 answers

Looking at the UITextViewDelegateprotocol , a new method to iOS7: textView:shouldInteractWithURL:inRange:.

, , attributedString range, , . , username.

.

[attributedString addAttribute:NSLinkAttributeName
                         value:[@"username://" stringByAppendingString:username]
                         range:range];

- :

- (BOOL)textView:(UITextView *)textView shouldInteractWithURL:(NSURL *)URL inRange:(NSRange)characterRange
{
    if ([URL.scheme isEqualToString:@"username"]) {
        [self doSomethingWithUserName:URL.host];
        return NO;
    }

    return YES;
}

, " " WWDC 2013.

+7

HTML- UIWebView

<div> Here goes the text. <a href="/users/Username">@Username</a> <a href="/tags/mytag">#mytag</a>. </div>

, - webView:shouldStartLoadWithRequest:navigationType:. URL- , . NO , - .

+1

DTCoreText, , . HTML, , , .

. <UITextInput>, , , "".

0
source

All Articles