XLPagerTabStrip Button Bar width wider than navigation bar - ios

I am implementing a ButtonBarPagerTabStripViewController with two buttons on my navigation controller's navigation bar. I followed the example provided by adding the following into viewDidLoad()
self.buttonBarView.backgroundColor = UIColor.clear
self.settings.style.buttonBarItemsShouldFillAvailableWidth = true
self.buttonBarView.removeFromSuperview()
self.navigationController?.navigationBar.addSubview(buttonBarView)
However when the Button Bar loads in the navigation bar the width of the Button Bar exceeds the width of the navigation bar. This leaves me with the following:
How can I fix this so that all the buttons fill the width of the navigation bar but do not exceed the width of the navigation bar?

Connecting the containerView outlet to a UIScrollView in Interface Builder fixed this problem for me.

Related

View doesn't go under status bar and status bar is black

I'm hiding the Navigation Bar on one of the screens, and if is set:
navigationController?.navigationBarHidden = true
The status bar becomes black. Also, the image doesn't fit all the screen (see the screenshot).
If I comment this line, Navigation bar stays on screen, and the status bar is white.
Full code:
override func viewWillAppear(animated: Bool) {
navigationController?.navigationBarHidden = true
navigationController?.navigationBar.setBackgroundImage(UIImage(), forBarMetrics: .Default)
navigationController?.navigationBar.translucent = true
navigationController?.navigationBar.backgroundColor = UIColor.clearColor()
navigationController?.view.backgroundColor = UIColor.clearColor()
All constraints of ImageView are set to 0 and it's set to fill the screen:
So, I want to put ImageView under the status bar and make the status bar icons/text white. What I'm doing wrong?
You're not doing anything "wrong". You have set the top of the image view to the bottom of the view controller's top layout guide. Well, that's the bottom of the status bar — exactly where you see the top of the image view.
If you want the image view to underlap the status bar, its top needs to be pinned to the top of the main view, not the top layout guide.
And if you want the status bar to change text color, you need to implement preferredStatusBarStyle to return .LightContent. If this means that the result of preferredStatusBarStyle has changed, you would need to call setNeedsStatusBarAppearanceUpdate to alert the runtime to this fact.
To place the image view under the status bar, and have the image view fill the UIViewControllers view:
Clear all constraints for the image view
Add a constraint to set the image view to have the same width as the parent view
Add a constraint to set the image view to have the same height as the parent view
Pin the image view to the nearest neighbor as shown below. Add the constraints
The final constraints will look like the following:

Prevent UISearchDisplayController from hiding under the navigation bar on iPad

I have a tableview with view with search bar on top of the screen below navigation bar. There is also tab bar on this screen. When search controller is activated first, time search bar hides under navigation bar (Translucent set to NO).
In viewDidLoad, searchDisplayControllerDidEndSearch and searchDisplayControllerWillBeginSearch I am setting the search bar frame:
self.searchDisplayController.searchBar.frame=CGRectMake(0, 0, width, 44);
I am not using AutoLayout

Set image view underneath the navigation bar

In my UIViewController I have UIImageView that takes up the full size of the controller (screen) and serves as a background. On top of UIImageView I have a UITableView with a clear background. I set the navigation bar to translucent like this:
self.navigationController.navigationBar.translucent = YES;
UIImageView is underneath the navigation bar as I want it to be. Unfortunately the same happens to UITableView. I want to put UITableView at the bottom of navigation bar, leaving UIImageView underneath. If I set:
[self setEdgesForExtendedLayout:UIRectEdgeBottom]
then UITableView is at the bottom of the navigation bar, but the same happens also to UIImageView. What would be the easiest solution to leave UIImageView underneath the navigation bar and push down the UITableView at the bottom of the navigation bar?
By default in iOS 7 the content extends to the top and bottom of the screen, underneath any navigation bars, tool bars, or tab bars. If you were to set the frame of the table view to be start after the navigation bar, the content of the table view would not scroll beneath the navigation bar providing the nice blur effect.
What you'll probably want to do instead, is keep the y origin of your table view at 0, underneath the navigation bar, and set the content inset so the content starts after the navigation bar.
This is pretty simple. If you're using auto layout the top layout guide of the view controller will recognise the height of the status bar and navigation bar so you don't need to calculate this yourself. The bottom of the navigation bar should end at 66.
//Using Auto Layout
CGFloat navigationBarHeight = self.topLayoutGuide.length;
//Not using Auto Layout
UINavigationBar *nav = self.navigationController.navigationBar;
CGFloat navigationBarHeight = nav.frame.origin.y + nav.frame.size.height;
myTableView.contentInset = UIEdgeInsetsMake(navigationBarHeight, 0, 0, 0)
And of course if you actually do want the frame to start after the navigation bar the height above stays the same, you just need to manually set the frame of the table view.
CGRect tableViewFrame = self.view.bounds;
tableViewFrame.origin = CGPointMake(tableViewFrame.origin.x, navigationBarHeight);
tableViewFrame.size = CGSizeMake(tableViewFrame.size.width, tableViewFrame.size.height - navigationBarHeight*2);
myTableView.frame = tableViewFrame;
EDIT: Ah, almost forgot. You'll also want to change the scrollIndicatorInsets to match the contentInset, so your scroll bars don't move offscreen.
myTableView.scrollIndicatorInsets = myTableView.contentInset;

Image view hide navigation bar in scroll view

In my ipad app, there is one navigation bar and one image view within scroll view.
When i run my app, the image view hide the navigation bar.
So, i remove image view and run again, then i see navigation bar.
But, i can't click the button in navigation bar.
Please, tell me how can i solve it?
Keep in mined the hierarchy of the view , if the UIScrollView is on top of the views , then any view behinde it will not receive any touch event.
The navigation bar added with XIB is a part of the subviews in you main view so you have to start the UIScrollView under the navigation bar , y = 44
ScrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 44, self.view.frame.size.width,self.view.frame.size.height-44)];
and do not forget to subtract 44 from the ScrollView height to fit the screen.

ios changing navigation bar height causes leftBarButtonItem not to be centered

I'm working on a project that needs to have the navigation bar height bigger than the default.
This is how i set the nav bar height:
- (CGSize)sizeThatFits:(CGSize)size {
if (iPad) {
CGSize newSize = CGSizeMake(768,86);
return newSize;
}
return CGSizeMake(320, 44);}
I set an bg image for the navigation bar and that's working ok.
The problem is that the back button and the right button item are not centered.
Does anyone know how to center them?
Thanks
It's generally bad practice to manipulate the navigation bar's height. I tried to do it a number of different ways for one project and every approach had a "gotcha". Namely, the navigation buttons are always justified to the bottom of the navigation bar, so adjusting it's height will cause the buttons to look like they're rendering towards the bottom of the bar. And the buttons will animate oddly as you push and pop other controllers. I would suggest not adjusting the height of the navigation bar.

Resources