Graphical issue with UISearchBar on iOS 7 - ios

I have graphical issues using the UISearchBar.How can I fix it ?
here's my code:
[self.view addSubview:self.resultObject.searchBar];
I have add
self.searchBar.frame = CGRectMake(0, 0, 320, 1);
[self.searchBar sizeToFit];
to viewDidLoad but I still have the same problem.
Thank you a lot

You should place your search bar at (0, viewController.topLayoutGuide.length); you are adding it at (0,0). In iOS7, views are by default under the status bar.

Related

UINavigationBar title text partially appears on screen

I am creating a UINavigationBar programmatically, which is displaying as intended in iOS 7. However, in iOS 8.x all the text in the UINavigationBar doesn't appear within the bounds of the screen. One of my assumptions is this has something to do with Auto Layout.
//ViewControllerRootHomeCenter.m
_navBar = [[UINavigationBar alloc] init];
_navBar.frame = CGRectMake(0,0, self.view.frame.size.width, 64);
// add hambuger menu
//...etc etc
[self.view addSubView:_navbar];
You can try to obtain the screen width this way too:
CGRect frame = (CGRect){0,0,CGRectGetWidth([[UIScreen mainScreen]bounds]),64);
Perhaps it will fix your problem.
First of all, make sure you're not hard-coding the width of the navigation bar.
UINavigationBar *navBar = [[UINavigationBar alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 44)];
Secondly, if your auto layout is enabled, make sure there are no conflicting constraints. If it's not enabled, then I don't see why you should be having this problem.

Two problems with UISearchBar when it is embedded in UINavigationBar

I set a default background image for UISearchBar:
[[UISearchBar appearance]setSearchFieldBackgroundImage:[UIImage imageNamed:#"search_field"] forState:UIControlStateNormal];
I then have a UISearchBar set to the nav bar's titleView.
UIView *searchView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 200, 35)];
lsearchBar = [[TestSearchBar alloc]initWithFrame:searchView.frame];
[searchView setBackgroundColor:[UIColor clearColor]];
[searchView addSubview:lsearchBar];
But the result looks horrible with a crushed graphic for my search bar:
If it try to embed it without using UIView directly, like this:
lessonsSearchBar = [[TestSearchBar alloc] initWithFrame:CGRectMake(0, 0, 200, 35)];
self.navigationItem.titleView = lessonsSearchBar;
it looks better, but when I push segue to the next view controller, or do pop back with animation it tries to animate it and looks horrible with this gray bar around it:
I do try it inside UIView because I also want to set a custom size to my UISearchBar and realign it a bit to the left side of the screen, which for some reason is not allowed when I set my search bar directly to navitationItem.titleView. I'm not sure exactly how to achieve this without crashing my image (which I set with setSearchFieldBackgroundImage) or without those glitches with animation. Can you please help?

ios7 status bar overlaps toolbar when using container view

I´v read the posts regarding this issue but found nothing to work, I think it must be since I am using a toolbar and have the View Controller embedded in a container view. The status bar always overlaps. No matter if I try to replace the toolbar or set different settings in IB. It also seems that since it´s inside a container view, setting the inferred option does not work. I even tried putting two toolbars on top, but only this one shows.
The status bar in iOS 7 is transparent, so if you want to have a look similar to that of iOS6, create a view of 20 pixels and add it inside your "container" view...
UIView *statusBarView = [[UIView alloc] initWithFrame: CGRectMake(0, 0, 320, 20)];
statusBarView.backgroundColor = [UIColor blackColor];
[containerViewController.view addSubview:statusBarView];
Then set the frame of your "contained" ViewController accordingly
containedViewController.frame = CGRectMake(0, 20, 320, itsCurrentHeight - 20);
This way the status bar should not overlap with your content anymore

UITabBarController not responding

I'm using a UITabBarController with UINavigationControllers like this
I add this to the view using
tabctrl.view.frame = CGRectMake(0, 0, 320, 548);
[self.view addSubview:tabctrl.view];
The screen looks like
But I can't switch to other tab(ie, touching on tabctrl's tab has no response)
If I change the frame like
tabctrl.view.frame = CGRectMake(0, 0, 320, 488);
then the screen looks like,
Now, I can touch the tab and switch to required viewcontroller. How to solve this issue?
I need to get access to the tabctrl when its frame height is 568.
I'm using xcode 4.6.2 and ios simulator 4inch retina.
Use this code:
[appDelegate.window setRootViewController:tabctrl];
rather than:
tabctrl.view.frame = CGRectMake(0, 0, 320, 568);
[self.view addSubview:tabctrl.view];
Your tabbar controller might be behind something else on the bottom of the screen. You can test it with code:
[self.view bringSubviewToFront: tabctrl]
If this fixes your problem, try to find which view is in front of your tabbar controller
Set your rootViewController's wantsFullScreenLayout property to YES
tabbarController.wantsFullScreenLayout = YES
This should solve your tabbar switching issue on 4-inch screen

UINavigationController's view and 20 points offset

This is an already posted question but I need to understand what is going on with the following scenario. I'm developing an iPad application and I created a UINavigationController like the following (test purposes).
UINavigationController* navigationController = [[UINavigationController alloc] init];
navigationController.view.backgroundColor = [UIColor redColor];
Once created, I added the UINavigationController's view as a subview of a UIViewController.
[self.view addSubview:navigationController.view];
The result is displayed in the following image:
As you can see, there is a gap between the status bar and the navigation bar of the UINavigationController. Since the view of the UINavigationController is red, it seems that the frame of the navigation bar has that gap.
I've found an hack to fix the problem. By setting the frame for the UINavigationController, the navigation bar goes in the right position.
CGRect statusBarFrame = [[UIApplication sharedApplication] statusBarFrame];
CGRect frameRect = CGRectMake(navigationController.view.frame.origin.x, navigationController.view.frame.origin.y - statusBarFrame.size.height, navigationController.view.frame.size.width, navigationController.view.frame.size.height);
navigationController.view.frame = frameRect;
Now, since I don't like very much that hack and I would understand what is going on, do you have any suggestions to find an elegant solution to resolve the problem?
Thank you in advance.
That 20px offset is for status bar, navigation controller is designed to be full-screen, but you are adding it to the subview of the main view.
viewController setWantsFullScreenLayout:YES
It may help you.
This is the fix that really solved all the problem. So thought of posting it as it might really.
How this works
This gonna set my navigation bar origin to 0, and in turn the view of navigation is also set to 0 which takes the reference of Navigation Bar, which solves all the mess :)
And 44 is the heigh of Navigation Bar in the code. :)
Put the code in ViewDidAppear,
CGRect windowFrame = [UIScreen mainScreen].applicationFrame;
//Setting the Origin to 0 of both Navigation Bar and Navigation View for Both Landscape and Portrait
if (UIDeviceOrientationIsPortrait([UIDevice currentDevice].orientation)){
[self.navigationController.navigationBar setFrame:CGRectMake(0, 0, windowFrame.size.width, 44)];
[self.navigationController.view setFrame:CGRectMake(0, 0, windowFrame.size.width, windowFrame.size.height)];
}
else{
[self.navigationController.navigationBar setFrame:CGRectMake(0, 0, windowFrame.size.height, 44)];
[self.navigationController.view setFrame:CGRectMake(0, 0, windowFrame.size.height, windowFrame.size.width)];
}
[self setWantsFullScreenLayout:<#(BOOL)#>];
is deprecated. If you want to add subviews to your ViewController without worrying about NevigationBar use:
self.edgesForExtendedLayout = UIRectEdgeNone;

Resources