0

I have the following code setup in iOS using objective C, however the part addint the link only works for ranges starting at 30 or less. The length of short_content should always be at least 100 words.

NSString *short_content = [self getFirstNWords:100 :content];
NSString *link = @" \nClick here to read more   ";
NSMutableAttributedString *str = [[NSMutableAttributedString alloc] initWithString:[short_content stringByAppendingString:link]];

[str addAttribute: NSLinkAttributeName value:@"http://mytest.com/" range:NSMakeRange(str.length - 100, short_content.length)];

1 Answers1

1

If you want to set the range of the "link" part of the string, then you want:

[str addAttribute: NSLinkAttributeName value:@"http://mytest.com/" range:NSMakeRange(str.length - link.length, link.length)];
rmaddy
  • 314,917
  • 42
  • 532
  • 579