0

Hello I am trying to tappable UILabel similar to Facebook's like text, Label's text would be similar to

"You, Steve and 50 others like this."

Where "You", "Steve" and "50 others" should be tappable separately.

I am trying my luck with NSAttributedString but it is not helping me, Can anyone help me to find a way ?

rmaddy
  • 314,917
  • 42
  • 532
  • 579
Abhishek
  • 1,682
  • 2
  • 17
  • 29

1 Answers1

1

try this, but it's not for label but it's for textView.

    NSMutableAttributedString * string = [[NSMutableAttributedString alloc] initWithString:@"firstsecond"];
[string addAttribute:NSForegroundColorAttributeName value:[UIColor redColor] range:NSMakeRange(0,5)];
[string addAttribute:NSForegroundColorAttributeName value:[UIColor greenColor] range:NSMakeRange(5,6)];




//[string addAttribute:NSUnderlineStyleAttributeName value:[NSNumber numberWithInt:10] range:NSMakeRange(0,5)];

[string addAttribute:NSLinkAttributeName value:[NSURL URLWithString:@"http://www.google.co.in"] range:NSMakeRange(0,5)];



[string addAttribute:NSLinkAttributeName value:[NSURL URLWithString:@"http://www.yahoo.com"] range:NSMakeRange(5,6)];



self.txtView.attributedText=string;
self.txtView.scrollEnabled = NO;
self.txtView.editable = NO;
self.txtView.textContainer.lineFragmentPadding = 0;
self.txtView.textContainerInset = UIEdgeInsetsMake(0, 0, 0, 0);
self.txtView.delegate = self;
 }
- (BOOL)textView:(UITextView *)textView shouldInteractWithURL:(NSURL *)url inRange:        (NSRange)characterRange
 {
    return YES;
  }
Sheshnath
  • 3,293
  • 1
  • 32
  • 60