我正在製作一個應用程序,其中包含最新的公司新聞部分。基本上這個計劃最初是使用ASIHTTPRequest來提取所有的HTML,通過它搜索標籤,然後將信息提取出來用於新聞標題和描述,然後在我的應用程序的滾動視圖中顯示它作爲計劃文本。然而,這被證明是一場噩夢,因爲該網站沒有模式顯示信息。從UIWebView中顯示的URL中刪除超鏈接
我已經決定在顯示最新公司新聞的UIWebView中顯示URL。我希望這是一個頁面視圖,因此我的用戶無法導航到網站的其他方面。是否有可能停止顯示爲鏈接的網站超鏈接?我的UIWebView代碼如下;
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];
任何幫助,將不勝感激。 謝謝
編輯:我也嘗試添加以下;
webNews.dataDetectorTypes = UIDataDetectorTypeNone;
這對鏈接的檢測沒有任何區別。
設置UIDataDetectorTypeNone並不奇怪。所有的鏈接仍然是可點擊的。即使通過界面生成器取消選中框也沒有區別。今晚我會嘗試你的最後一條建議,謝謝。 –
您肯定可以禁用鏈接,使其可以通過shouldStartLoadWithRequest委託進行點擊。至於禁用鏈接顯示爲鏈接,則基於上面示例中顯示的方式使用正確的CSS規則。也許有一個更好的CSS方法,但是我沒有那麼好在CSS – Lefteris
我已經實現了[webNews stringByEvaluatingJavaScriptFromString:@「document.styleSheets [0] .addRule(\」a.link \「,\」color:#FF0000 \ 「)」];在 - (void)webViewDidFinishLoad:(UIWebView *)webView委託方法中,它沒有區別。所有鏈接仍然可點擊 –