objective c - Detect hash tags #, mention tags @, in iOS like in Twitter App -
objective c - Detect hash tags #, mention tags @, in iOS like in Twitter App -
i need observe #tags given in description uilabel , alter text color [uicolor bluecolor]; not able alter particular text colors in uilabel blue. using uilabel in custom uitableviewcell. there way solve issue differentiate #tags , normal text text colors ? can help me solve ?
-(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]; (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 text field or label show result // yourtextfield.attributedtext = attstring; // // yourlabel.attributedtext = attstring; homecoming attstring; }
ios objective-c uitableview uilabel hashtag
Comments
Post a Comment