I am using NIAttributedLabel
for displaying links on text.
NIAttributedLabel *label;
label = [[NIAttributedLabel alloc] initWithFrame:rect];
label.delegate = self;
label.font = [UIFont fontWithName:@"Helvetica" size:MAIN_FONT_SIZE];
label.textAlignment = UITextAlignmentLeft;
label.lineBreakMode = UILineBreakModeWordWrap;
label.numberOfLines = 0;
label.backgroundColor = [UIColor clearColor];
label.highlightedTextColor = [UIColor whiteColor];
label.text = strEditedText;
label.textColor = [UIColor blackColor];
[label setTextColor:[UIColor blueColor]
range:[strEditedText rangeOfString:stringPh]];
But last line is not working correctly although stringPh is in strEditedText. All the text is coming in blue.
I set up an example which you can download here, and I found that it worked perfectly.
With:
the simulator correctly highlights the right portion of the text:
Are you absolutely sure your string
stringPh
is an actual substring ofstrEditedText
?