Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Detect hash tags #, mention tags @, in iOS like in Twitter App

I need to Detect #Tags given in description UILabel and change text color as [UIColor BlueColor]; where i am not able to change particular text colors in UILabel to Blue. Now i am Using this UILabel in custom UITableViewCell. is there any way to solve this issue to differentiate #Tags and normal text by Text Colors ? can anybody help me to solve this ?

like image 486
Grey_Code Avatar asked Jun 23 '14 06:06

Grey_Code


People also ask

How do you find out if a hashtag is being used?

You can also check out how many people are using hashtags on Instagram by typing it into the search bar and tapping the Tags section. Click on each tag to see how many posts are using that hashtag, if anyone you follow is using that hashtag, as well as related popular hashtags.

How do I track a hashtag?

Socialert is an easy to use tool for hashtag tracking that gives you a quick overview of hashtag performance for free. Enter a hashtag, keyword, @mention, accounts which the tool then uses to generate an automatic report so you can start digging into social media platforms like Twitter.

Can you track a hashtag on Instagram?

You can track Instagram hashtags on your own, but the best way to approach this task is to use an Instagram hashtag analytics tool. A dedicated tool will track hashtag usage, identify top trending hashtags within your industry, and help you post more relevant content your audience will interact with.


1 Answers

-(NSMutableAttributedString*)decorateTags:(NSString *)stringWithTags{


    NSError *error = nil;

    //For "Vijay #Apple Dev"
    NSRegularExpression *regex = [NSRegularExpression regularExpressionWithPattern:@"#(\\w+)" options:0 error:&error];

    //For "Vijay @Apple Dev"
    //NSRegularExpression *regex = [NSRegularExpression regularExpressionWithPattern:@"@(\\w+)" options:0 error:&error];

    NSArray *matches = [regex matchesInString:stringWithTags options:0 range:NSMakeRange(0, stringWithTags.length)];
    NSMutableAttributedString *attString=[[NSMutableAttributedString alloc] initWithString:stringWithTags];

    NSInteger stringLength=[stringWithTags length];

    for (NSTextCheckingResult *match in matches) {

        NSRange wordRange = [match rangeAtIndex:1];

        NSString* word = [stringWithTags substringWithRange:wordRange];

        //Set Font
        UIFont *font=[UIFont fontWithName:@"Helvetica-Bold" size:15.0f];
        [attString addAttribute:NSFontAttributeName value:font range:NSMakeRange(0, stringLength)];


        //Set Background Color
        UIColor *backgroundColor=[UIColor orangeColor];
        [attString addAttribute:NSBackgroundColorAttributeName value:backgroundColor range:wordRange];

        //Set Foreground Color
        UIColor *foregroundColor=[UIColor blueColor];
        [attString addAttribute:NSForegroundColorAttributeName value:foregroundColor range:wordRange];

        NSLog(@"Found tag %@", word);

    }

    // Set up your text field or label to show up the result

    //    yourTextField.attributedText = attString;
    //
    //    yourLabel.attributedText = attString;

    return attString;
}

enter image description here

like image 110
Vijay-Apple-Dev.blogspot.com Avatar answered Sep 30 '22 16:09

Vijay-Apple-Dev.blogspot.com