status bar overlaps with navigation bar - iphone

I am adding navigation controller through code, in my application. All other thing work fine, but my navigation bar overlaps with the status bar.I have tried by adding  
if ([self respondsToSelector:#selector(edgesForExtendedLayout)])
self.edgesForExtendedLayout = UIRectEdgeNone;
but it is not working.
My other controllers in that navigation controller are in xibs only not storyboard.
Please help.

If you really don't want your Navigation Bar to be translucent then use this code and your problem will be solved :
self.navigationController.navigationBar.translucent = NO;

I solved the problem with the following code (as suggested by Tacettin Özbölük):
if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7.0) {
UIView *addStatusBar = [[UIView alloc] init];
addStatusBar.frame = CGRectMake(0, 0, 320, 20);
addStatusBar.backgroundColor = [UIColor colorWithRed:0.973 green:0.973 blue:0.973 alpha:1]; //change this to match your navigation bar
[self.window.rootViewController.view addSubview:addStatusBar];
}

Related

iOS spacing issue with translucent navigation bar

I'm currently having a UIViewcontroller with a 3-segment UISegmentedControl that when clicked switches view controllers displayed. The navigation bar and tab bar of this view are translucent.
I initialize the view like this:
- (void)viewDidLoad {
[super viewDidLoad];
[self setAutomaticallyAdjustsScrollViewInsets:YES];
self.segControl = [[UISegmentedControl alloc] initWithItems:[NSArray arrayWithObjects:#"View 1",#"View 2",#"View 3",nil]];
[self.segControl setTintColor:[[ConstantsSingleton sharedConstants] default_bg_Color]];
[self.segControl setSegmentedControlStyle:UISegmentedControlStyleBar];
[self.segControl addTarget:self action:#selector(segmentChanged:) forControlEvents:UIControlEventValueChanged];
[self.segControl setSelectedSegmentIndex:0];
self.navigationItem.titleView = self.segControl;
//Setting up the first viewcontroller
UIViewController *vc = [self viewControllerForSegmentIndex:self.segControl.selectedSegmentIndex];
[self addChildViewController:vc];
vc.view.frame = self.contentView.bounds;
[self.contentView addSubview:vc.view];
self.currentViewController = vc;
}
The contentView is a IB defined UIView with 0 leading and trailing on all sides (so basically it fills the parent view).
I switch viewcontrollers the following way:
-(void)segmentChanged:(UISegmentedControl *)sender {
UIViewController *vc = [self viewControllerForSegmentIndex:sender.selectedSegmentIndex];
[self addChildViewController:vc];
[self transitionFromViewController:self.currentViewController toViewController:vc duration:0.5 options:UIViewAnimationOptionTransitionFlipFromRight animations:^{
vc.view.frame = self.contentView.bounds;
[self.currentViewController.view removeFromSuperview];
[self.contentView addSubview:vc.view];
} completion:^(BOOL finished) {
[vc didMoveToParentViewController:self];
[self.currentViewController removeFromParentViewController];
self.currentViewController = vc;
}];
self.navigationItem.title = vc.title;
}
Now whenever I run this with a opaque navigation bar and tab bar this works fine, but whenever I try to use a translucent navigation bar and/or tab bar only the first view gets resized/its insets adjusted properly to not be behind the translucent navigation bar and/or tab bar. The second and third view will still appear behind them when they appear on screen.
It doesn't matter which viewcontroller is set as the first viewcontroller, all lead to the same behaviour.
What could be causing this issue and is there a way to solve this without resolving to manual contentinset adjustments.
I would suggest to enable the option Extend Edges in the property inspector of you're view.
Here's a good stackoverflow post differentiating the various layout settings for iOS 7 and up:
Explaining difference between automaticallyAdjustsScrollViewInsets, extendedLayoutIncludesOpaqueBars, edgesForExtendedLayout in iOS7

How to resize custom UISegmentedControl inside navigation bar for iPad?

I am new in iPhone app development. I am using customized uisegmentedcontrol inside navigation bar.
This code works well for iPhone.
[self.navigationItem setHidesBackButton:YES animated:YES];
profileSegmentControl = [[UISegmentedControl alloc]initWithItems:[NSArray arrayWithObjects: #"seg1", #"seg2", #"seg3", #"seg4", nil]];
[profileSegmentControl addTarget:self action:#selector(seg1Button) forControlEvents:UIControlEventValueChanged];
**profileSegmentControl.frame = CGRectMake(40, 25, 310, 30);**
profileSegmentControl.segmentedControlStyle = UISegmentedControlStyleBar;
profileSegmentControl.momentary = YES;
//[profileSegmentControl sizeToFit];
UIBarButtonItem *profileSegmentBarItem = [[UIBarButtonItem alloc] initWithCustomView:profileSegmentControl];
self.navigationItem.rightBarButtonItem = profileSegmentBarItem;
Now, when I change the orientation from portrait to landscape, how to change the uisegmentedcontroll buttons' co-ordinates in CGRectMake? When in landscape, the width should be 510 instead of 310.
Cannot use [segmentControlObject sizeToFit] as i have hidden the "back" navigation button of navigation bar. I tried this, but the width of segmentedControl does not cover the entire navigation bar.
I am aware of (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation method, but you cannot call this under viewDidLoad or under any method.
Using xcode 4.6
Do like this
if( [UIApplication sharedApplication].statusBarOrientation == UIInterfaceOrientationPortrait ){
FACING = #"PU";
}
if( [UIApplication sharedApplication].statusBarOrientation == UIInterfaceOrientationPortraitUpsideDown ){
FACING = #"PD";
}
if( [UIApplication sharedApplication].statusBarOrientation == UIInterfaceOrientationLandscapeLeft ){
FACING = #"LL";
}
if( [UIApplication sharedApplication].statusBarOrientation == UIInterfaceOrientationLandscapeRight ){
FACING = #"LR";
}
So set the frame whatever you want in the respective blocks.it works.

How to make a UITableViewController transparent on the top?

In my iPhone application I have presented controller:
ShareResourceItemViewController* controller = [[ShareResourceItemViewController alloc] initWithSharedResourceItem:[selectedItems objectAtIndex:0]];
[self presentViewController:controller animated:YES completion:nil];
Then in this controller I want to make it transparent on the top. I tried:
-(void)viewDidLoad{
[super viewDidLoad];
[self performSelector:#selector(test) withObject:nil afterDelay:3];
}
-(void)test{
self.tableView.backgroundColor = [UIColor clearColor];
self.tableView.opaque = NO;
self.tableView.backgroundView = nil;
}
The background was cleaned but controller is not transparent and I can not see previous controller? How can I fix this?
Make the tableview cells background color also to clear color.
Try this.
self.view.backgroundColor = [UIColor clearColor];
I think that if you want to see your previous View Controller, you want to not present a new view controller, but rather, put a new UIView on top of your View Controller. View Controllers can't be transparent or not, but views can. Give it a try:
ShareResourceItemViewController* controller = [[ShareResourceItemViewController alloc] initWithSharedResourceItem:[selectedItems objectAtIndex:0]];
[self.view addSubview:controller.view];

Implement Search Bar in iphone Mail app to shift up nav bar and search bar to reveal scope bar

I would like to implement a search bar with the exact same behavior as the mail app on the iphone. I cannot get the scopebar to reveal itself smoothly while the navigation bar and search bar are shifting upwards the way the mail program does it. In the mail app the nav bar and search bar move up to reveal the scopebar. How would i implement that kind of animation?
I did something crude:
- (BOOL)searchBarShouldBeginEditing:(UISearchBar *)searchBar {
searchBar.scopeButtonTitles = [NSArray arrayWithObjects:#"Button",#"Titles",#"Go",#"Here",nil];
searchBar.showsScopeBar = YES;
[searchBar setShowsCancelButton:YES animated:YES];
[self.navigationController setNavigationBarHidden:YES animated:YES];
self.tableView.contentOffset = CGPointMake(0, 0);
[searchBar sizeToFit];
return YES;
}
the search bar is allocated in my viewdidload as follows:
UISearchBar *searchBar = [[UISearchBar alloc] initWithFrame:CGRectMake(0, 0, 320, 44)];
searchBar.delegate = self;
self.tableView.tableHeaderView =searchBar;
[searchBar release];
In my viewwillappear i offset the table view to hide the search bar under the nav bar:
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
self.tableView.contentOffset = CGPointMake(0, 44);
}
Thanks!
Try sending -setNavigationBarHidden:animated: to the navigation bar in - searchBarTextDidBeginEditing:.

iphone - Search bar disappears from my root view controller

I have a search bar in my main screen - root table view controller. If I browse other screens and come back, sometimes, the search bar disappears. Here's my code.
searchBar = [[UISearchBar alloc] initWithFrame:CGRectMake(0, 0, self.tableView.frame.size.width, 44.0)];
searchBar.delegate = self;
searchBar.tintColor = [UIColor blackColor];
[searchBar sizeToFit];
self.tableView.tableHeaderView = searchBar;
searchDisplayController = [[UISearchDisplayController alloc]
initWithSearchBar:searchBar contentsController:self];
searchDisplayController.delegate = self;
searchDisplayController.searchResultsDataSource = self;
searchDisplayController.searchResultsDelegate = self;
Is there anything wrong with my code or is it one of the quirks of SDK 3.0?
I stumbled across this same issue recently and was able to narrow it's occurrence down to only when the search bar is out of sight (i.e. the table view has been scrolled), then navigated away from, then return to and scrolled back into sight. I have been unable to find any information on what the cause is, but I was able to workaround it by placing this:
self.tableView.tableHeaderView = searchBar;
in either the viewWillAppear or viewDidAppear event of my controller class. I'm assuming the code you've posted is from the viewDidLoad method of your controller class?