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;
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); indicator.center = self.view.center; [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:
So based on the CSS from the thread I mentioned, this should work:
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:
- XCTest build errors for test target Xcode 5:
- Override ringer volume in iPhone apps
- Getting exception as “Collection was mutated while being enumerated”
- Pinterest integration in ios app?
- UITableView dynamic cell heights only correct after some scrolling
- Programmatically setting tabBarItem title in Swift
- Xcode set default button on enter when making a form
- What tool(s) can I use to produce iPhone App Screencasts?
- How can I use .xcconfig files in Xcode 4?
- Get System Volume iOS
- how to calculate the current speed and average speed of user travelling from current location to particular loaction in map in iphone
- Core Location not working in iOS 8
- Conditional enum switch with stored enum
- Error (“'()' is not identical to 'UInt8'”) writing NSData bytes to NSOutputStream using the write function in Swift
- 'iostream' file not found error occur in xcode 4.5?