It is better to use a web view instead of UIButton and UILabel (disable the scrolling ).
Load the text in the webview as ,
webview.delegate=self;
[webview loadHTMLString:@"<html><head></head><body><a href=\"name_identifier\"><b>Kobe Bryant</b></a> is a very good basketball player who is coming off an serious injury.</body></html>" baseURL:nil];
Listen for the URL
- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)aRequest navigationType:(UIWebViewNavigationType)navigationType{
if([[[aRequest URL] absoluteString] isEqual:@"name_identifier"]){
//TODO:Do the steps to call when press on the name
return NO;
}
return YES;
}
For performing the Segue action
- Remove the segue from UIButton
- ctrl+drag from the source UIViewController to destination UIViewController.
- select "push".
- Give an identifier to the segue.
And add the below line to go to the next view controller.
(before return NO;
in the above code)
[self performSegueWithIdentifier: @"segue_id" sender:self];
You can disable the scrolling of the web view as,
webView.scrollView.scrollEnabled = NO;
webView.scrollView.bounces = NO;
And can calculate the dynamic height as,
CGSize maximumSize = CGSizeMake(320,568); //change as you wish
CGSize expectedLabelSize = [contentString sizeWithFont:fontUsed
constrainedToSize: maximumSize
lineBreakMode:NSLineBreakByCharWrapping];
Set the new height as,
[webview sizeThatFits: expectedLabelSize];
or
CGRect newFrame = webview.frame;
newFrame.size.height = expectedLabelSize.height;
webview.frame = newFrame;
Hope this may help you.