UINavigationBar title text partially appears on screen - ios

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.

Related

iOS - NavigationItem titleView is centered on first load, but then becomes pinned to top left

I added a UISegmentedControl programmatically to navigationItem.titleView
The first time it is displayed it is centered like I would expect. But as soon as I dive down into a detail view controller, I can see my titleView's view pushed into the upper left corner, and nothing I've tried gets it back
In my initialization method I do this
UISegmentedControl *segmentedControl = [[UISegmentedControl alloc] initWithItems:segmentTextContent];
segmentedControl.selectedSegmentIndex = 0;
[segmentedControl setTranslatesAutoresizingMaskIntoConstraints:NO];
segmentedControl.autoresizingMask = UIViewAutoresizingFlexibleWidth;
//segmentedControl.frame = CGRectMake(0, 0, 280.0f, 30.0f);
self.navigationItem.titleView = segmentedControl;
I realized after a while that setting the CGRectMake has no affect
I've also tried putting this login in viewDidAppear but also did not change this outcome
Previously, when I tried putting a UISegmentedControl inside of another UIView, I lost the ability to click on the UISegmentedControl (I'm not sure if I had a variation of this which solved my positioning problems though)
If you only have 2 segments I don't think it's needed for the resizing, its width will always fit even for iPhone 4 and lower.
What happens if you remove the following:
[segmentedControl setTranslatesAutoresizingMaskIntoConstraints:NO];
segmentedControl.autoresizingMask = UIViewAutoresizingFlexibleWidth;

Navigation bar title is not centred in iPhone's portrait mode

I have created a ViewController Using Xib file of size wAny and hAny and i have used autolayaout and constraint to fit UI all devices and all orientation.
Everything is working fine but when i'm running app on iPhone portrait mode title of navigation bar is not centred where as when rotating it to landscape mode title is centred.
I have used following code for setting title
self.title = #"Download Schedule";
Already tried:
I have tried to set custom UILabel of lesser font size to Navigation bar's title view but still i'm getting it on left side .
Here is code of my right button
//add right bar button for more options
UIView *navBarButtonsView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 44, 44)];
UIBarButtonItem *item0 = [UIBarButtonItem negativeSpacerWithWidth:5];
UIButton *moreButton = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 44, 44)];
[moreButton setBackgroundImage:[UIImage imageNamed:#"ic_web"] forState:UIControlStateNormal];
[moreButton addTarget:self action:#selector(addNewSchedule) forControlEvents:UIControlEventTouchDown];
[navBarButtonsView addSubview:moreButton];
UIBarButtonItem *backButton = [[UIBarButtonItem alloc] initWithCustomView:navBarButtonsView];
self.navigationItem.rightBarButtonItems = [NSArray arrayWithObjects:item0, backButton, nil];
There is something else going on - something you have not told us about. I suspect that there is something wrong with how you are setting your rightButtonItems, such that there are invisible buttons taking up the space on the right. I can reproduce this issue only by deliberately making the right button really wide:
So I suspect you have applied a large width to the right button, or there are extra invisible right button items taking up the space on the right.

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

Graphical issue with UISearchBar on iOS 7

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.

Resources