iphone:searchbar remove background when interface changes - iphone

I have used this code to remove background behind searchbar but when I rotate the view to Landscape or launch the application in landscape view a black container is displayed around searchbar
for (UIView *searchSubview in mySearchBar.subviews) {
NSLog(#"Subview: %#", searchSubview);
if ([searchSubview isKindOfClass:NSClassFromString(#"UISearchBarBackground")]) {
//[searchSubview removeFromSuperview];
[searchSubview setAlpha:0.0];
//[searchSubview setBackgroundColor:[UIColor clearColor]];
//break;
}
}
Please enlighten me on this. I tried to implement this code in willRotate, shouldRotate and didRotate methods but problem persist. Please enlighten me on this.
Regards
Ankit

got it ....
open the interface builder
under searchbar attributes in view, Mode is set as 'Redraw' set it to scaleToFill

Related

background color in above (bounce part) of UIWebView

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

UISearchBar No Background Landscape Mode

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

How do I code for the landscape orientation in iPhone?

I understand that I can change what interface orientations are supported, but if I want the landscape view to be entirely different, or somewhat different than the portrait view, how do I code for it?
Thank you.
Just load another view controller when the orientation changes. To make things simple, I often use a hidden navigation controller and push and pop the views I want for any particular orientation.
Using a dedicated view controller for each orientation is the easiest approach.
If the only difference is presentation, not controller logic, then you could also try coding a single view controller to swap between two views depending on orientation.
E.g. pseudocode
UIView *landscapeView = ...;
UIView *portraitView = ...;
when orientationChanged
{
if landscape then
[portraitView setHidden:YES];
[landscapeView setHidden:NO];
self.view = landscapeView;
else if portrait then
[landscapeView setHidden:NO];
[portraitView setHidden:YES];
self.view = portraitView;
[self.view setNeedsDisplay];
}

UITabBar leaves a white rectangle when hidden

I have been unable to google an acceptable solution to this that can be applied to my project.
My app is a graphing tool that has three tabs; one for the graph itself and the other two are for browse/search functions for things that can be added to the graph. All tabs are navigation controllers.
The tab for the graph itself, when in portrait mode, displays a small preview of the graph and lists details of each entity that is on the graph below, and displays the tab bar at the bottom.
When the user rotates into landscape mode the graph turns full screen and everything else, including the tab bar, disappears. This is where I'm having the problem, as the GLView for my graph is always obscured by a white rectangle where the tab bar was.
I have tried changing the size of the navigation controllers view to full screen, changing the size of the tab bar controllers' view to full screen, changing the frame size of the tab bar itself to CGRect(0,0,0,0), becoming emotionally distraught, banging my fists on the desk, shouting abusive language at the MacBook, etc; all to no avail.
How can I make it work?
I had this problem, and I've resolved it by changing tabbar's subview frame for my content view (there are 2 subviews in tab bar - content view (#0) and bar view (#1)):
[[self.tabBarController.view.subviews objectAtIndex:0] setFrame:FULLSCREEN_FRAME];
I had the same problem and found the answer here : UIView doesn't resize to full screen when hiding the nav bar & tab bar
just resize the tabbarcontroller view this when you hide the tabbar :
tabBarController.view.frame = CGRectMake(0, 0, 320, 480);
It seems to have the problem with hiding the Bottom bar as Tab bar.... which I was facing and googled a lot for this.I consider it as a bug with this tab bar.Then also....we can use some trick.....
You can try for this and will definitely help if you are trying to hide the tab bar and which leaves the white space..
for the hell of coding you need to write just
[self setHidesBottomBarWhenPushed:YES];
when you are pushing to other view,where you don't need the Tab bar just write it
twitDetObj=[[TwitDetail alloc] initWithNibName:#"TwitDetail" bundle:nil];
[self.navigationController pushViewController:twitDetObj animated:YES];
self.hidesBottomBarWhenPushed=YES;
[twitDetObj release];
Hope this will work for you.....
This one works for me:
[[self.tabBarController.view.subviews objectAtIndex:0] setFrame:CGRectMake(0, 0, 320, 480)];
I had this code within the tab's viewControllers.
NOTE - This solution is to just to remove white space left after hiding tab bar.
For hiding tab bar best solution is - #Michael Campsall answer here
The simplest solution to this is to change your view's(in my case its tableView) bottom constraints, instead of giving bottom constraints with BottomLayoutGuide give it with superview. Screenshots attached for reference.
Constraints shown in below screenshots creates the problem, change it according to next screenshot
.
Actual constraints to remove white space should be according to this(below) screenshot.
For those who is still struggling with this. I have found that the problem lays on the constraints. Tab Bar is hidden, yet it already changed my constraint from Storyboard.
SWIFT 3+
self.tabBarController?.tabBar.isHidden = true
let cons = NSLayoutConstraint(item: textview, attribute: NSLayoutAttribute.bottom,
relatedBy: NSLayoutRelation.equal, toItem: self.view,
attribute: NSLayoutAttribute.bottom, multiplier: 1.0, constant: 0)
view.addConstraints([cons])
In my case "textview" was the item, which supposed to fill the white space from hidden TabBar.
Are you sure it's obscured and not just A) not redrawn or B) the frame of your GLView doesn't occupy that space?
some of the superviews of currentViewController.view of the tab bar view controller has clipToBounds set to YES (it's class name is UITransitionView, if not mistaken). To access it use
tabBarController.currentViewController.view.superview.superview.clipToBounds = NO;
after doing this your attempts of resizing a view will not be limited by anything and will succeed. Good luck!
This is just a workaround, but have you tried presenting the graph modally when the user rotates to landscape? This should obscure the tab bar.
You can avoid the transition with
[viewController presentModalViewController:graph animated:NO]
its because the space where tab bar was , not allocated to other views when u set tab bar hidden u can set the corresponding view to stretch or fill the whole screen like scale fill or aspect fill something like that or take a view bigger than the iphine screen so that when u change the phone to landscape it can complete fill the screen
Check the UIView underneath. It may be set to white, so when you hide the tab you're revealing the white UIView. Try setting the UIView to Transparent.
I think u need to set self.navigationController.view.frame to full size ie to UIApplication screen frame before u set tabbar hidden
On after unhiding tababr and reaching to particular view. Tabbar was showing white space on above uitababr. This solved my problem
-(void)viewWillAppear:(BOOL)animated
{
[[self.tabBarController.view.subviews objectAtIndex:0] setFrame:CGRectMake(0, 0, 320, 568)];
}
in the view pushed
- (BOOL)hidesBottomBarWhenPushed
{
return YES;
}
- (void)hidesTabBar:(BOOL)hidden {
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0];
for (UIView *view in self.tabBarController.view.subviews) {
if ([view isKindOfClass:[UITabBar class]]) {
if (hidden) {
[view setFrame:CGRectMake(view.frame.origin.x, [UIScreen mainScreen].bounds.size.height, view.frame.size.width , view.frame.size.height)];
} else {
[view setFrame:CGRectMake(view.frame.origin.x, [UIScreen mainScreen].bounds.size.height - 49, view.frame.size.width, view.frame.size.height)];
}
} else {
if([view isKindOfClass:NSClassFromString(#"UITransitionView")]) {
if (hidden) {
[view setFrame:CGRectMake(view.frame.origin.x, view.frame.origin.y, view.frame.size.width, [UIScreen mainScreen].bounds.size.height)];
} else {
[view setFrame:CGRectMake(view.frame.origin.x, view.frame.origin.y, view.frame.size.width, [UIScreen mainScreen].bounds.size.height - 49 )];
}
}
}
}
[UIView commitAnimations];
}
My solution: set self.edgesForExtendedLayout = .None in your view controller's viewDidLoad().
I'm assuming that you've already checked the autoresizing arrows on your view?
Have you tried hiding the UITabBar with
tab_bar.hidden = YES

How to Change Background of UIWebView Scrolling?

in the iPhone SDK Interface Builder, any UIWebView has a default gray background that is shown when the view has been scrolled too far. Is it possible to change this background color so it doesn't look so obvious? The gray conflicts with my App :( Any help would be greatly appreciated.
webView.backgroundColor = yourcolor;
You can even do it in IB.
id scrollView = [[[self yourWebView] subviews] objectAtIndex:0];
if([scrollView respondsToSelector:#selector(setBackgroundColor:)] )
{
[scrollView performSelector:#selector(setBackgroundColor:)
withObject:[UIColor groupTableViewBackgroundColor]];
}