Can#39;t change background for UIWebView in iOS(无法在 iOS 中更改 UIWebView 的背景)
问题描述
有没有办法改变 UIWebView 的背景颜色?
Is there a way to change background color for UIWebView?
IB 中设置的所有颜色均未影响 UIWebView 行为:在加载实际内容之前,它显示为白色(在加载和呈现内容之间导致白色闪烁).
None of the colors set in IB effect UIWebView behavior: before actual content is loaded it shows as up as white (causing a white flash between the moment it is loaded and content is rendered).
以编程方式设置背景颜色也不做任何事情.
Setting background color programmatically does not do anything either.
代码如下:
@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];
}
推荐答案
可以将webview的opaque属性设置为NO,然后设置下view的背景色.
You can set the opaque property of the webview to NO and then set background color of the view beneath.
[webView setOpaque:NO];
这篇关于无法在 iOS 中更改 UIWebView 的背景的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:无法在 iOS 中更改 UIWebView 的背景
基础教程推荐
- 如何比较两个 NSDate:哪个是最近的? 2022-01-01
- iOS - UINavigationController 添加多个正确的项目? 2022-01-01
- Play 商店的设备兼容性问题 2022-01-01
- UIImage 在开始时不适合 UIScrollView 2022-01-01
- SwiftUI-ScrollViewReader的ScrollTo不滚动 2022-01-01
- 如何将图像从一项活动发送到另一项活动? 2022-01-01
- Xcode UIView.init(frame:) 只能在主线程中使用 2022-01-01
- Android Volley - 如何动画图像加载? 2022-01-01
- 为什么姜饼模拟器方向卡在应用程序中? 2022-01-01
- navigationItem.backBarButtonItem 不工作?为什么上一个菜单仍然显示为按钮? 2022-01-01
