Skip to content

Instantly share code, notes, and snippets.

@stigi
Created September 1, 2011 13:34
Show Gist options
  • Select an option

  • Save stigi/1186172 to your computer and use it in GitHub Desktop.

Select an option

Save stigi/1186172 to your computer and use it in GitHub Desktop.
diff --git a/OHAttributedLabelTest/RootViewController.m b/OHAttributedLabelTest/RootViewController.m
index 13ca5ef..547d928 100644
--- a/OHAttributedLabelTest/RootViewController.m
+++ b/OHAttributedLabelTest/RootViewController.m
@@ -86,6 +86,7 @@
NSString *baseString = [self.wordList objectAtIndex:indexPath.row];
NSMutableAttributedString *attributedString = [NSMutableAttributedString attributedStringWithString:baseString];
+ [(OHAttributedLabel*)[cell viewWithTag:1337] removeAllCustomLinks];
[(OHAttributedLabel*)[cell viewWithTag:1337] setAttributedText:attributedString];
NSString *urlString = [NSString stringWithFormat:@"user://%@", baseString];
[(OHAttributedLabel*)[cell viewWithTag:1337] addCustomLink:[NSURL URLWithString:urlString] inRange:[baseString rangeOfString:baseString]];
@AliSoftware
Copy link

@RickiG, @stigi

What a coincidence, actually for my own app FoodReporter I did a correction in OHAttributedLabel's setAttributedText: method no later than this morning, so that each time the text is modified, the custom links are removed. I guess this correction makes sense as if you modify the attributedText, the custom links you previously set with given ranges don't make sense anymore.

I planned to commit this simple correction this weekend (or even maybe tomorrow), didn't realize our problems had the same origin ;)
I'll keep you posted as soon as I commited my correction, so that you would not even need to take care of removing custom links you may have previously set!

Note: In the future I guess it would be much more logical that the NSAttributedString itself keep track of the custom links (by adding an attribute to a range of the AttributedString itself and not add the custom link on OHAttributedLabel), but I guess then the whole link detection code and rendering links in blue, underlined whould then need to be refactored... and I don't think I'll have time for this kind of refactoring soon :-/

@AliSoftware
Copy link

@stigi just to let you know that I just commited a new version on github that fixes this issue: all custom links are removed each time you change the text or attributedText of the OHAttributedLabel (as they don't have any sense any more anyway).

Thanks for the help!

@stigi
Copy link
Author

stigi commented Sep 2, 2011

great :)
thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment