从UIWebView中显示的URL中删除超链接 [英] Removing hyper links from a URL shown in UIWebView

查看:85
本文介绍了从UIWebView中显示的URL中删除超链接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在创建一个应用程序,其中包含最新公司新闻的部分。基本上,该计划最初是使用ASIHTTPRequest来提取所有HTML,通过它搜索标签,然后将信息拉出来获取新闻标题和描述,然后将其显示为我的应用程序滚动视图中的计划文本。然而,这被证明是一场噩梦,因为该网站没有信息显示方式。

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.

我已经决定在UIWebView中显示URL显示最新的公司新闻。我希望这是一个单页面视图,因此我的用户无法导航到该网站的其他方面。是否可以阻止站点超链接显示为链接?我的UIWebView代码如下:

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. Thanks

编辑:我也尝试添加以下内容;

I have also tried adding the following;

webNews.dataDetectorTypes = UIDataDetectorTypeNone;

这对链接的检测没有区别。

Which makes no difference to the detection of links.

推荐答案

好的,为dataDetectorTypes设置UIDataDetectorTypeNone应该阻止webview检测链接,这是正确的。

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

此外,使用

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

UIWebview委托,您只需为您不希望用户允许的URL返回NO以下...

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

此外,您可以在页面完成加载后插入自定义CSS规则

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

- (void)webViewDidFinishLoad:(UIWebView *)webView 

委托方法,这样:

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

所以基于我提到的线程中的CSS,这应该有效:

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;\")"];

这篇关于从UIWebView中显示的URL中删除超链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆