Removing hyper links from a URL shown in UIWebView

I am making an app which has a section for latest company news. Basically the plan was initially to use ASIHTTPRequest to extract all the HTML, search through it for tags then pull the information out for news title and description then display it as just plan text in a scroll view of my app. However, this was proving to be a nightmare as the site has no pattern to the way the information is displayed.

I have since decided to display the URL in a UIWebView which shows the latest company news. I want this to be a one page view so my user cannot navigate to other aspects of the site. Is it possible to stop the sites hyperlinks showing up as links? My code for the UIWebView is as follows;

  • NSMutableString as retain/copy
  • Calculate max font size that fits in a rect?
  • Navigation bar appear over the views with new iOS7 SDK
  • Problem doing logic tests after XCode 3.2.4 upgrade
  • Create xib based interface with Xcode 5
  • What is a “delegate” in Objective C's iPhone development?
  • UIView *webNewsView = [[UIView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]];
    self.view = webNewsView;    
    CGRect webFrame = [[UIScreen mainScreen] applicationFrame];
    webFrame.origin.y = 0.0f;
    webNews = [[UIWebView alloc] initWithFrame:webFrame];
    webNews.backgroundColor = [UIColor clearColor];
    webNews.scalesPageToFit = YES;
    webNews.autoresizingMask = (UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight);
    webNews.delegate = self;
    [self.view addSubview: webNews];
    [webNews loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://myURLHere"]]];
    indicator = [[UIActivityIndicatorView alloc]initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
    indicator.frame = CGRectMake(0.0, 0.0, 25.0, 25.0); =;
    [self.view addSubview: indicator];

    Any help would be appreciated.

    EDIT: I have also tried adding the following;

    webNews.dataDetectorTypes = UIDataDetectorTypeNone;

    Which makes no difference to the detection of links.

    2 Solutions Collect From Internet About “Removing hyper links from a URL shown in UIWebView”

    OK, setting the UIDataDetectorTypeNone for dataDetectorTypes, should prevent the webview from detecting the links, this is correct.

    Furthermore using the

    - (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType 

    UIWebview delegate, you can simply return NO for the URL’s you don’t want the user to allow following…

    Furthermore, you can insert custom CSS Rules, after the page has finished loading in the

    - (void)webViewDidFinishLoad:(UIWebView *)webView 

    delegate method, this way:

    [MywebView stringByEvaluatingJavaScriptFromString:@"document.styleSheets[0].addRule(\"\", \"color:#FF0000\")"];

    So based on the CSS from the thread I mentioned, this should work:

    [MywebView stringByEvaluatingJavaScriptFromString:@"document.styleSheets[0].addRule(\".active\", \"pointer-events: none;\");document.styleSheets[0].addRule(\".active\", \"cursor: default;\")"];

    One thing you can also do here to further customize your links in the web view is edit the html string you are passing into the webview. Specifically, you can add CSS to the html to determine how links will be shown (colors, underlines, etc). Here is a code snippet which takes an html string and customizes it with CSS:

    NSString *HTML = [NSString stringWithFormat:@"<html>\n"
                          "<style type=\"text/css\">\n"
                          "body {font-family: \"%@\"; font-size: %@; color:#%@; background-color:#FFFFFF; margin: 0; padding: 0; line-height: 1.5; }\n"
                          "a:link {color:#00B0EA; text-decoration: none;}\n"
                          "<body><script type=\"text/javascript\">window.onload = function() { window.location.href = \"ready://\" + document.body.offsetHeight; } </script>%@</body>\n"
                          font.familyName, @(font.pointSize), colorHexString, htmlBodyString];