UIWebView's content background color not transparent - ios

I'm using an UIWebView to load some HTML text from a plist.
I managed to make its background transparent using
webView.opaque = NO;
webview.backgroundColor = [UIColor clearColor];
but the content, which is the text loaded from the plist, is shown with a disturbing white background.
I'm loading it using
NSString *descr = [NSString stringWithFormat:#"<html><head><style> body{font-size:16; font-family: Helvetica; color: black;} strong{font-family: Arial; font-weight: bold; font-size:16} .bg{background:transparent;}</style></head><body><div class='bg'>%#</div></body></html>",[item valueForKey:#"description"]];
[webView loadHTMLString:descr baseURL:nil];
I've tried setting the .bg class background color to rgba(255,0,0,0.0), but nothing worked.
Also tried setting webView.scrollView.backgroundColor : [UIColor clearColor];
Any advice on how to get the UIWebView's content background transparent?

try this !
[webView setOpaque:NO];
webView.bakgroundColor = [UIColor clearColor];

In XCode 6.x uncheck Opaque and change Background's opacity to 0%. I think other XCode versions will also work.

Your HTML body will still have a background color.
You need to add 'background-color:transparent;' to the body part of your CSS
See here: https://stackoverflow.com/a/3935033/78496

Related

iOS 8 Text Field Tint Color

In iOS 7, changing the 'tint color' attribute of a uitextfield would change the cursor color of that text field. In iOS 8, even when I change the global storyboard tint color, this does not occur (objective-c, still works in iOS 7). How do I fix this?
I just tried to replicate your problem but both on iOS7.1 and iOS8 the tintColor attribute of a textfield works perfectly.
This line of code change the cursor color of the textField. Try this instead of changing the tint color in Storyboard
textField.tintColor = [UIColor colorWithRed:98.0/255.0f green:98.0/255.0f blue:98.0/255.0f alpha:1.0];
Hope it helps!
try the following:
[[self.textField setTintColor:[UIColor blueColor]];
[self.textField setTintAdjustmentMode:UIViewTintAdjustmentModeNormal];
Looking to actually put a tinted color filter on the whole view, not just change cursor color?
Look no further. .tint is a lame name because it in no way implies that it adjusts the cursor color. Naturally, people googling about the .tint property are likely trying to find a way to apply a color filter across the whole frame/region of their UIView, UITextView, whatever.
Here is my solution for you:
I made macros for this purpose:
#define removeTint(view) \
if ([((NSNumber *)[view.layer valueForKey:#"__hasTint"]) boolValue]) {\
for (CALayer *layer in [view.layer sublayers]) {\
if ([((NSNumber *)[layer valueForKey:#"__isTintLayer"]) boolValue]) {\
[layer removeFromSuperlayer];\
break;\
}\
}\
}
#define setTint(view, tintColor) \
{\
if ([((NSNumber *)[view.layer valueForKey:#"__hasTint"]) boolValue]) {\
removeTint(view);\
}\
[view.layer setValue:#(YES) forKey:#"__hasTint"];\
CALayer *tintLayer = [CALayer new];\
tintLayer.frame = view.bounds;\
tintLayer.backgroundColor = [tintColor CGColor];\
[tintLayer setValue:#(YES) forKey:#"__isTintLayer"];\
[view.layer addSublayer:tintLayer];\
}
To use, simply just call:
setTint(yourView, yourUIColor);
//Note: include opacity of tint in your UIColor using the alpha channel (RGBA), e.g. [UIColor colorWithRed:0.5f green:0.0 blue:0.0 alpha:0.25f];
When removing the tint simply call:
removeTint(yourView);

how to create UISegmentedControl to look like buttons on camera

I'd like to create a UISegmentedControl that's styled similarly to the flash and hdr controls in the camera app. (i.e. black outline, black text, frosted semi-translucent background)
Any suggestions to do this?
Thanks,
You might want to follow this tutorial http://www.raywenderlich.com/4344/user-interface-customization-in-ios-5 to understand how to customize UIKit controls with your own assets.
The idea is that you will use UIAppearance and will have to create a few assets for the various possible states (selected/unselected, left/right...)
#JP... Thanks for the answer. In the interim, I found a way to do it.
I'm placing the segmented controller as an overlay on a map to change the map's style (standard/satellite/hybrid) as in google maps. Note the subtle change in the background color - that's to increase readability on standard-style maps which tend do have a much lighter background than satellite-based images.
- (void) setMapSelectorColors:(UISegmentedControl *)control {
NSDictionary *mapStyleSelectorTextAttributes = [NSDictionary dictionaryWithObject:[UIColor blackColor] forKey:UITextAttributeTextColor];
[self.mapStyleSelector setTitleTextAttributes:mapStyleSelectorTextAttributes forState:UIControlStateNormal];
if (control.selectedSegmentIndex == 0) {
self.mapStyleSelector.tintColor = [UIColor lightGrayColor];
} else {
self.mapStyleSelector.tintColor = [UIColor whiteColor];
}
}

Transparent GPUImageView?

I am using a GPUImageView inside my iOS application. I want that the GPUImageView have a transparent background.
I tried setBackground:[UIColor clearColor]
It does not work.
Any workarounds?
Regards
I found you need to set both of these to get a transparent background. Neither works alone.
strengthPreviewImageView.backgroundColor = [UIColor clearColor];
[strengthPreviewImageView setBackgroundColorRed:0 green:0 blue:0 alpha:0];
...Did you try the method from the GPUImageView header?
- (void)setBackgroundColorRed:(GLfloat)redComponent green:(GLfloat)greenComponent blue:(GLfloat)blueComponent alpha:(GLfloat)alphaComponent;

iOS : WebView Background color to transparent

What I want is set the background color of webview to transparent.
Below is the code I am using for webview.
NSString *embedHTML = [NSString stringWithFormat:#"<html><body style=\"background-color: transparent;font-family: verdana;\"><h3>About US</h3></BODY></HTML>"];
[webView loadHTMLString:embedHTML baseURL:nil];
However when I use this, I still see background color as WHITE. Any idea how to get color to transparent?
This is all it should take,
[webView setBackgroundColor:[UIColor clearColor]];
[webView setOpaque:NO];
Just add this line.
webView.opaque=NO;

UIView clearColor produce WhiteColor instead of Transparent in IOS5 Xcode4.2

I am facing a very strange issue ever since I updated the Xcode with IOS 5 ...
I can't able to set the background Color of UIView to Transparent ...
here is What I can do :!!
I can set the view to any color , green , blue , red and they are all shown correctly on UIVIEW
[self.view setBackgroundColor:[UIColor greenColor]]; // Working 100 %
I can set a background Image // it's Working too
[self.view setBackgroundColor:[UIColor colorWithPatternImage:[UIImage imageNamed:#"abc2010.png"]]]; // Working 100 %
[self.view setBackgroundColor:[UIColor clearColor]]; // No Error but result is not what I need
instead of transparent Background , it is always WHITE ... !!
I'll appreciate the help in figuring out the problem!! :)
I've just had this same problem. Here's a couple things to do.
Firstly, make sure you set the view so it's not opaque:
[self.view setOpaque:NO];
Second, set the views layer so it's also clearColor:
[self.view.layer setBackgroundColor:[UIColor clearColor]];
See if that helps. It fixed my problem, and your's sounds just like mine.
Good luck.

Resources