有没有办法改变背景颜色UIWebView
?
IB效果UIWebView
行为中设置的颜色都没有:在加载实际内容之前,它显示为白色(在加载内容和呈现内容之间导致白色闪烁).
以编程方式设置背景颜色也不起作用.
这是代码:
@interface Web_ViewViewController : UIViewController { UIWebView *web; } @property (nonatomic, retain) IBOutlet UIWebView *web; @end .... -(void)viewDidLoad { super viewDidLoad; web.backgroundColor = [UIColor blueColor]; NSURL *clUrl = [NSURL URLWithString:@"http://www.apple.com"]; NSURLRequest *req = [NSURLRequest requestWithURL:clUrl]; [web loadRequest:req]; }
小智.. 180
您可以将webview的opaque属性设置为NO,然后设置下方视图的背景颜色.
[webView setOpaque:NO];
与`webView.bakgroundColor = [UIColor clearColor]`一起使用 (37认同)
这真的需要更多的选票.它比Adolfo的答案简单得多,而且效果很好(有了@ stigi的建议,没有它,你会得到一个灰色闪光而不是白色,这已经是一种改进). (6认同)
完美的工作.将webView设置为opaque可以让您看到webView的背景颜色.将它设置为像@stigi建议清除将让你看到webView背后的内容. (2认同)
Adolfo.. 17
试一试.一旦完成加载,它将淡化UIWebView,你将看不到闪存.
@interface Web_ViewViewController : UIViewController{ UIWebView *web; BOOL firstLoad; } @property (nonatomic, retain) IBOutlet UIWebView *web; @end ... (void)viewDidLoad { [super viewDidLoad]; firstLoad = YES; web.delegate = self; web.alpha = 0.0; NSURL *clUrl = [NSURL URLWithString:@"http://www.apple.com"]; NSURLRequest *req = [NSURLRequest requestWithURL:clUrl]; [web loadRequest:req]; } - (void)webViewDidFinishLoad:(UIWebView *)webView { if (firstLoad) { firstLoad = NO; [UIView beginAnimations:@"web" context:nil]; web.alpha = 1.0; [UIView commitAnimations]; } }
webViewDidFinishLoad中的动画块一旦加载就会淡出视图,或者如果你想让它弹出,那么只需删除UIView调用即可.
您可以将webview的opaque属性设置为NO,然后设置下方视图的背景颜色.
[webView setOpaque:NO];
试一试.一旦完成加载,它将淡化UIWebView,你将看不到闪存.
@interface Web_ViewViewController : UIViewController{ UIWebView *web; BOOL firstLoad; } @property (nonatomic, retain) IBOutlet UIWebView *web; @end ... (void)viewDidLoad { [super viewDidLoad]; firstLoad = YES; web.delegate = self; web.alpha = 0.0; NSURL *clUrl = [NSURL URLWithString:@"http://www.apple.com"]; NSURLRequest *req = [NSURLRequest requestWithURL:clUrl]; [web loadRequest:req]; } - (void)webViewDidFinishLoad:(UIWebView *)webView { if (firstLoad) { firstLoad = NO; [UIView beginAnimations:@"web" context:nil]; web.alpha = 1.0; [UIView commitAnimations]; } }
webViewDidFinishLoad中的动画块一旦加载就会淡出视图,或者如果你想让它弹出,那么只需删除UIView调用即可.
这里没有任何答案对我有用,它们都涉及到某种闪光.我在这里找到了一个有效的答案:http://www.iphonedevsdk.com/forum/iphone-sdk-development/4918-uiwebview-render-speeds-white-background.html(我必须将延迟调整为.25以避免闪烁).记得在InterfaceBuilder中检查UIWebView的"隐藏"标志.
- (void)webViewDidFinishLoad:(UIWebView *)webView { [self performSelector:@selector(showAboutWebView) withObject:nil afterDelay:.25]; } - (void)showAboutWebView { self.infoWebView.hidden = NO; }