Create an account

Very important

  • To access the important data of the forums, you must be active in each forum and especially in the leaks and database leaks section, send data and after sending the data and activity, data and important content will be opened and visible for you.
  • You will only see chat messages from people who are at or below your level.
  • More than 500,000 database leaks and millions of account leaks are waiting for you, so access and view with more activity.
  • Many important data are inactive and inaccessible for you, so open them with activity. (This will be done automatically)


Thread Rating:
  • 567 Vote(s) - 3.46 Average
  • 1
  • 2
  • 3
  • 4
  • 5
UIWebView background is set to Clear Color, but it is not transparent

#1
I'm developing an iOS 4 application using iOS SDK latest version and XCode 4.2.

I have a XIB with a `UIWebView` with **Alpha = 1.0**, **Background** set to **Clear Color** and **Opaque** is not set. On this XIB I setup an image as background with this code:

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
UIColor *background = [[UIColor alloc] initWithPatternImage:[UIImage imageNamed:@"AboutBackground.png"]];
self.view.backgroundColor = background;
[background release];
}
return self;
}

The `UIWebView` is showing an static html:

<html><head></head><body style=\"margin:0 auto;text-align:center;background-color: transparent; color:white\">...</body></html>

On iOS 5 simulator, its background is transparent, but on an iOS 4 device is grey.

Any clue?
Reply

#2
Besides setting your webview's background to clear color, also make sure that you set opaque to false.
Reply

#3
Also set :

[webView setBackgroundColor:[UIColor clearColor]];
[webView setOpaque:NO];
Reply

#4
/*for ios please set this*/

[webViewFirst setOpaque:NO];

/*for html please set this*/
<body style="background:none">
Reply

#5
webView.opaque = NO;

webView.backgroundColor = [UIColor clearColor];
Reply

#6
You can try this code (i know, that it's unsafe, but it works even for ios5):
<blink><pre><code>- (void)makeBodyBackgroundTransparent {
for (UIView *subview in [webView subviews]) {
[subview setOpaque:NO];
[subview setBackgroundColor:[UIColor clearColor]];
}
[webView setOpaque:NO];
[webView setBackgroundColor:[UIColor clearColor]];
}</code></pre></blink>
Reply

#7
NSString *content=@"example clear background color UIWebview";
NSString *style=[NSString stringwithformat:@"<html><head><style>body {background-color:transparent;}</style></head><body>%@</body></html>",content];
[myWebview loadhtmlstring:style baseurl:nil];
Reply

#8
For Objective

webView.opaque = NO;
webView.backgroundColor = [UIColor clearColor];

Please make sure to include this into your HTML code:

<body style="background-color: transparent;">
or


<body style="background:none">



Reply

#9
Latest Swift Version (as required):

lazy var webView: UIWebView = {
let view = UIWebView()
view.delegate = self
view.backgroundColor = .clear
view.isOpaque = false
return view
}()

*Remove delegate line if not required*
Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

©0Day  2016 - 2023 | All Rights Reserved.  Made with    for the community. Connected through