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:
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>
Any Solution?
try this...
webViewFirstTab.opaque=NO;
for (UIView* subView in [webViewFirstTab subviews])
{
if ([subView isKindOfClass:[UIScrollView class]]) {
for (UIView* shadowView in [subView subviews])
{
if ([shadowView isKindOfClass:[UIImageView class]]) {
[shadowView setHidden:YES];
}
}
}
}
This does not work for me on iOS6 or iOS7. The UIWebView holds a _UIWebViewScrollView which holds a UIWebBrowserView. Setting the backGround color of all 3 views to clear color does not result in a transparent background. I also have the html like this:
Anybody got this to work on iOS 6 or 7?
Related
I'm trying to create a custom keyboard for a UITextField, the background of this inputView should be transparent, I have set the background color in the view's xib file to "clear color". It is working great on iOS 6 and earlier.. but on iOS 7 it not working
Any idea how can I make it work? I want it to be fully transparent
This will set the backdrops opacity to zero when displaying your custom keyboard and reset it back to 1 when the normal keyboard is shown.
+ (void)updateKeyboardBackground {
UIView *peripheralHostView = [[[[[UIApplication sharedApplication] windows] lastObject] subviews] lastObject];
UIView *backdropView;
CustomKeyboard *customKeyboard;
if ([peripheralHostView isKindOfClass:NSClassFromString(#"UIPeripheralHostView")]) {
for (UIView *view in [peripheralHostView subviews]) {
if ([view isKindOfClass:[CustomKeyboard class]]) {
customKeyboard = (CustomKeyboard *)view;
} else if ([view isKindOfClass:NSClassFromString(#"UIKBInputBackdropView")]) {
backdropView = view;
}
}
}
if (customKeyboard && backdropView) {
[[backdropView layer] setOpacity:0];
} else if (backdropView) {
[[backdropView layer] setOpacity:1];
}
}
+ (void)keyboardWillShow {
[self performSelector:#selector(updateKeyboardBackground) withObject:nil afterDelay:0];
}
+ (void)load {
NSNotificationCenter *nc = [NSNotificationCenter defaultCenter];
[nc addObserver:self selector:#selector(keyboardWillShow) name:UIKeyboardWillShowNotification object:nil];
}
I am chasing the same issue, as I have a numeric keypad which fills only the left half of the screen in landscape mode (and is basically unusable on iOS7 where the blur effect covers the entire width of the screen). I haven't quite figured out how to get what I want (blurred background only behind my actual inputView), but I have figured out how to disable the blur entirely:
Define a custom subclass of UIView and specify that in your xib file
In this class override willMoveToSuperview: as follows
- (void)willMoveToSuperview:(UIView *)newSuperview
{
if (UIDevice.currentDevice.systemVersion.floatValue >= 7 &&
newSuperview != nil)
{
CALayer *layer = newSuperview.layer;
NSArray *subls = layer.sublayers;
CALayer *blurLayer = [subls objectAtIndex:0];
[blurLayer setOpacity:0];
}
}
This appears to impact the background of every custom inputView I have (but not the system keyboard) so you might need to save/restore whatever the normal opacity value is when your inputView gets removed from the superview if you don't want that.
iOS 7 is doing some things under the hood that are not documented. However, you can examine the view hierarchy and adjust the relevant views by overriding -willMoveToSuperview in your custom input view. For instance, this code will make the backdrop transparent:
- (void)willMoveToSuperview:(UIView *)newSuperview {
NSLog(#"will move to superview of class: %# with sibling views: %#", [newSuperview class], newSuperview.subviews);
if ([newSuperview isKindOfClass:NSClassFromString(#"UIPeripheralHostView")]) {
UIView* aSiblingView;
for (aSiblingView in newSuperview.subviews) {
if ([aSiblingView isKindOfClass:NSClassFromString(#"UIKBInputBackdropView")]) {
aSiblingView.alpha = 0.0;
}
}
}
}
I have a dark background with a UITableView on top of it. By default the section index is semi-transparent with a dark text colour. I'd like to change the text colour for the section index to the same colour as I have made the UITableViewCell title label. I have read around a bit and it seems you have to subclass the UITableView? How do I do this?
Since iOS 6 you have the possibility to do it like:
searchTable.sectionIndexColor = [UIColor blackColor];
To solve this I used the following in viewDidAppear:
for (UIView *subView in [self.view subviews])
{
if ([[[subView class] description] isEqualToString:#"UITableViewIndex"])
{
[subView performSelector:#selector(setIndexColor:) withObject:[UIColor whiteColor]];
}
}
Since it's not documented, it has to be through a selector.
As of iOS 6.0 there are two methods that allow you to change the color of the section indexes and the background shown when you drag the scrubber.
if ([tableView respondsToSelector:#selector(setSectionIndexColor:)]) {
tableView.sectionIndexColor = ... // some color
tableView.sectionIndexTrackingBackgroundColor = ... // some other color
}
Of course this will only execute if the device has 6.0+. With any older iOS, nothing will change.
I think this shouldn't be a big problem, but I can't find the solution on my own. As always :p I have an UIWebView that has background color set to clearColor but when I try to scroll down too much I get the "bouncing area" above loaded HTML in dark gray color. I would like to change this to transparent/white. Is there any way of changing this?
Digression: I read that classes inheriting UIScrollView can have property bounce = NO and then they won't show the bouncing area at all. Even if UIWebView was inheriting that class I wouldn't like to stop it from bouncing, just "bounce it in white" so to speak...
Thanks a lot,
Luka
Take a look at the following answer
Remove gradient background from UIWebView?
Set the webview's background colour and set opaque to NO:
[self.webView setBackgroundColor:[UIColor whiteColor]];
[self.webView setOpaque:NO];
Or try setting clear color as background:
[self.webView setBackgroundColor:[UIColor clearColor]];
[self.webView setOpaque:NO];
#Ladislav: thanks for pointing me to the right subject :)
Now, the following post Remove gradient background from UIWebView? is exactly what I needed, so I am sorry I opened the new thread. I searched the forum but since there is no name for this gradient, bounce background or background I couldn't find it earlier.
The summary would be:
1.Setting the backgroundColor of web view to clearColor !in code! cause in interface builder is not producing the wanted result.
myWebView.backgroundColor = [UIColor clearColor];
this line will only make the "overscroll" background look lighter, but to remove it totally (make it transparent/white) we need to hide all imageViews found in subViews of our myWebView:
for (UIView* subView in [self.myWebView subviews])
{
if ([subView isKindOfClass:[UIScrollView class]]) {
for (UIView* shadowView in [subView subviews])
{
if ([shadowView isKindOfClass:[UIImageView class]]) {
[shadowView setHidden:YES];
}
}
}
}
Thanks everyone, I wish you a great weekend
I have the following snippet to remove the background from a UISearchBar:
for (UIView *subview in self.searchDisplayController.searchBar.subviews)
{
if ([subview isKindOfClass:NSClassFromString(#"UISearchBarBackground")])
{
[subview removeFromSuperview];
break;
}
}
However, if the device is rotated to landscape a black background appears behind the search bar. Any ideas how to fix it? I'm not exactly sure if this is undocumented.
Thanks!
I just ran across this problem and found little help searching. Unfortunately, removing the feature was not an option so I had to figure it out. It seems as the the UISearchBar view has a background that goes black when you change orientation. So my code now looks like this:
[searchBar setBackgroundColor:[UIColor clearColor]];
for (UIView *subview in searchBar.subviews)
{
if ([subview isKindOfClass:NSClassFromString(#"UISearchBarBackground")])
[subview removeFromSuperview];
}
Given the undocumented nature, I removed the feature. Appears to be a bug due to the undocumented call.
got it ....
open the interface builder under searchbar attributes in view, Mode is set as 'Redraw' set it to scaleToFill
Is there a way to get a black keyboard? The default one is bluish. And the Alert style one is semi-transparent black. I was wondering if it was possible to have the keyboard black, e.g. non transparent. Or do I have to pull up a black view behind the keyboard to reduce the transparency effect?
The short answer is, NO. The only two keyboards you can display are the normal and alert style keyboards.
There are ways to hack around, get the ui keyboard and change it's composition. I wouldn't recommend doing this as it will 1) likely make have your app rejected from the app store and 2) likely break the next time an iOS revision comes around.
Seems like putting a black or white view behind the keyboard should work for application. In this case I would recommend looking here for a way to animate that black view up below the keyboard.
As Ben states above you can just use one of these two values:
[textView setKeyboardAppearance:UIKeyboardAppearanceAlert];
[textView setKeyboardAppearance:UIKeyboardAppearanceDefault];
Here is code to remove the UIKeyboard background by hiding it. Feel free to modify it to tint the UIKeyboard:
-(NSArray*)subviewsOfView:(UIView*)view withType:(NSString*)type{
NSString *prefix = [NSString stringWithFormat:#"<%#",type];
NSMutableArray *subviewArray = [NSMutableArray array];
for (UIView *subview in view.subviews) {
NSArray *tempArray = [self subviewsOfView:subview withType:type];
for (UIView *view in tempArray) {
[subviewArray addObject:view];
}
}
if ([[view description]hasPrefix:prefix]) {
[subviewArray addObject:view];
}
return [NSArray arrayWithArray:subviewArray];
}
-(void)removeKeyboardBackground{
for (UIWindow *keyboardWindow in [[UIApplication sharedApplication] windows]) {
for (UIView *keyboard in [keyboardWindow subviews]) {
for (UIView *view in [self subviewsOfView:keyboard withType:#"UIKBBackgroundView"]) {
view.hidden=YES;
}
}
}
}
Just call [self removeKeyboardBackground] after you received a NSNotification for UIKeyboardDidShowNotification. Do whatever you want with the background view by replacing view.hidden=YES; with whatever you would like.