Can't change background for UIWebView in iOS

前端 未结 8 1183
小鲜肉
小鲜肉 2020-12-12 20:20

Is there a way to change background color for UIWebView?

None of the colors set in IB effect UIWebView behavior: before actual content is l

相关标签:
8条回答
  • 2020-12-12 21:16

    Give this a try. It will fade the UIWebView in once it has finished loading and you won't see the flash.

    @interface Web_ViewViewController : UIViewController <UIWebViewDelegate> {
    
    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];
        }
    }
    

    The animation block in webViewDidFinishLoad will fade the view in once it's loaded, or if you prefer to have it pop on then just remove the UIView calls.

    0 讨论(0)
  • 2020-12-12 21:17

    None of the answers here worked for me, they all involved still some sort of flash. I found a working answer here: http://www.iphonedevsdk.com/forum/iphone-sdk-development/4918-uiwebview-render-speeds-white-background.html (I had to adjust the delay to .25 to avoid the flashing). Remember to check the UIWebView's "hidden" flag in InterfaceBuilder.

    - (void)webViewDidFinishLoad:(UIWebView *)webView 
    {
        [self performSelector:@selector(showAboutWebView) withObject:nil afterDelay:.25];          
    }
    
    - (void)showAboutWebView 
    {
        self.infoWebView.hidden = NO;
    }
    
    0 讨论(0)
提交回复
热议问题