为了修复 ios 中链接的 UITextview 蓝色问题(我想要白色链接),我在自定义弹出窗口中实现了 UIWebview
在我的弹出控制器中,我有以下代码( uiwebview 在 xib 中设置为隐藏)
- (void) showWebView:(NSString *)htmlText{
[webView setHidden:FALSE];
[txtContent setHidden:TRUE];
NSString * htmlString = [NSString stringWithFormat:@"<html><head><style type='text/css'>body {background-color:transparent; } p { color:white; font-family:Helvetica; font-size:14px; } a { color:white; }</style></head><body><p>%@</p></body></html>", htmlText];
webView.delegate = self;
NSLog(@"htmlstring %@",htmlString);
[webView loadHTMLString:htmlString baseURL:nil];
}
(txtContent 是我隐藏的 uiTextview)
在我的主控制器中,我有以下内容:
SwbPopup * popup = [[SwbPopup alloc] initWithNibName:@"SwbPopup" bundle:nil];
[[self.view superview] addSubview:popup.view];
popup.view.center = CGPointMake([self.view superview ].center.y, [self.view superview].center.x - ([self.view superview].frame.size.width / 4) );
[popup showWebView:popupBloodglucoseLevel];
(popbloodglucoselevel 是一个字符串,其中包含我的弹出消息和链接)
当我不在xib中隐藏webview时,它确实显示(每次)但也不想加载html....
更新 我实现了以下所有委托方法,但没有一个被调用:s
- (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error
{
//[myActivityIndicatorView stopAnimating];
NSLog(@"ERROR");
NSLog([NSString stringWithFormat: @"%d", [error code]]);
}
- (void)webViewDidStartLoad:(UIWebView *)webView{
NSLog(@"Started loading");
}
- (void)webViewDidFinishLoad:(UIWebView *)webView{
NSLog(@"Finished loading");
}