I have a UILabel which shows the String. I need to change the color of the particular texts in the UILabel and when clicking on those texts it should open two different links in a webview. How to achieve this: The following code i have written:
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithString:@"This is Yahoo and Google" attributes:nil];
[attributedString addAttribute: NSForegroundColorAttributeName
value: [UIColor redColor]
range: NSMakeRange(8,5)];
[attributedString addAttribute: NSFontAttributeName
value: [UIFont fontWithName:@"Helvetica" size:15]
range: NSMakeRange(8,5)];
[attributedString addAttribute: NSFontAttributeName
value: [UIFont fontWithName:@"Didot" size:24]
range: NSMakeRange(18,6)];
self.linkLabel.attributedText = attributedString;
}
Now i want when the user clicks on google it should open google.com and when the user taps Yahoo it should open yahoo.com. how is ti possible?