Why it happens like this?
The last one "plus" is just an ADD System Item.
Is there a way to prevent from such issue?
In UINavigationBar the space between items is fixed and you either have to set rightNavigationItems array or leftNavigationItems array. Then you don't have opportunity to adjust spacing between items yourself. If you have customized view and UINavigationBar is not inside a UINavigationController then probably you can replace it with UIToolbar and add FlexibleSpace between each item. It will give you the same result but also it will adjust itself according to screen width.
I added 7 buttons in interfacebuilder the upper one is UINavigationBar and lower one is UIToolbar with FlexibleSpace item between each UIBarButtonItem
And This is what I got the result on iPhone4 Simulator
It looks like the space for the "add" item is a bit smaller and leads the item to internally used textfield less space making the text shrink to fit size, its only a guess.
Maybe/surly you can solve the issue using a custom item, but this would obviously not explain what is going on...
Related
In a UIViewController, I'd like to show two tabs in a UINavigationBar. I want the UINavigationItems to have similar behavior to UITabBarItems in a UITabBarController. I want the NavBar to be visible in both view controller tabs, and I want to change the color of the tab title in the navBar if the tab is selected.
Is there a simple and elegant way to conveniently set text/selectedText or image/selectedImage and create UINavigationItems that have behavior similar to UITabBarItems, including the ability to have the nav bar space the items out evenly, just like in a UITabBarController?
It would be great if I could set this like it can be done in a tabBar:
UITabBarItem *tabBarItem = [[UITabBarItem alloc] initWithTitle:title image:titleBlack selectedImage:titleRed];
The goal is to have two tabs, that change color if they are selected and they would be evenly spaced across the bar. I know I could do something simple like add two items to a navBarArray, but in order to have them spaced evenly across the bar for all screen widths, how would I do that? Is there an elegant solution?
This example shows the first tab selected. If I select the 2nd tab, I want Tab2 to be red and Tab1 to be black. This is just text, but if I have to create an image to accomplish this, I will.
This question is not a duplicate of the many questions on S.O. that are referring to displaying both a UITabBarController and a UINavigationController in the same app. This is different because I don't want a UITabBarController(I already have one that does something else- but I don't want to overcomplicate my question)- I just want to mimic this behavior, inside of a UINavigationBar. Please please please do not tell me I shouldn't do it this way. That's just another way to say "I don't feel like helping you figure this out."
I've tried looking for clean, simple, elegant solutions. I haven't found any. A complete example would be appreciated. Thanks =)
I came up with a solution that works well enough for me. I created a custom label with 2 buttons and a view with a height of 1 to act as a separator. I moved the UITableView down to pin the top of it to the UIView You could easily add more buttons if you desire to have more than 2.
In the viewDidLoad method: self.navigationController.navigationBarHidden = YES;
In viewDidAppear method: [self.navigationController setNavigationBarHidden:YES animated:YES];
Create a custom UILabel, pin the leading, top, and trailing to the superView, and set the desired height constraint.
Create a custom UIViewwith a height constraint of 1 (to act as the visual separator between the custom Navigation Bar and UITableView, pin the trailing and leading edges to the superView, and pin the bottom space of the UIView to the bottom space of the custom UILabel. Set the desired color for the separator.
Create two UIButtons, drag them into the label, and set these constraints:
-pin the UIButton center Y's to the center Y of the UILabel
-pin Button1's trailing to Button2's leading edge to each other and to the horizontal center of the superview
-Pin Button 1's leading and Button2's trailing to the superView
-Pin the top of the UITableView to the bottom of the UILabel
Set the UIButton color to change when selected, and set their targets as you would with any UIButton
Add any missing constraints in case I forgot to mention some.
Here is what it looks like:
I'm trying to make an app with a toolbar that can be resized. Basically, the toolbar can alternate between being at the bottom of the view and being at the top. When a button is pressed, it switches from one to the other. The problem is that when it is at the top, I want the size of the toolbar to expand to accommodate the status bar, but I don't know how to do this.
I've seen some solutions for changing the toolbar size but they all seem static and not something that can be changed with the tap of a button. Any suggestions on how to do this? Perhaps a different solution altogether?
You can use a normal UIView and customize it so it looks like a UIToolbar, then just set constraints using AutoLayout and animate the height-constraint.
I am trying to implement a simple mobile browser in iOS. I am trying to include two UIToolbars; one at the top and one at the bottom. The top toolbar will consist of a UITextField and a GO button. The bottom toolbar will consist of back and forward buttons.
I want this to work correctly in both portrait and landscape modes. However, I noticed that autolayout does not work for UIToolbar items. So I cannot set constraints for my UITextField and the buttons. How do I fix this?
Yes autolayout does not work for UIToolbar items because they are mostly UIBarItem instead of subclass of UIView.
You can still set up constraints by using special items
I have a UITabBarController like this:
As you can see, the 'Discover' and 'Requests' titles are compressed by high amounts of kerning. They are also slightly clipped at the end of each item title. Is there any way to fix this?
P.S. The problem does not appear on iPhone 6 and 6+, only 5S and below.
It seems like there is an issue with UITabBars where, if they deem their frame too small, they'll attempt to kern the item title labels to fit.
This issue with frame size can happen either from manually setting the frame of the UITabBar or possibly by having a larger number of items than will comfortably fit on screen (in your case 5).
In my experience with this issue, someone had erroneously set the frame of the UITabBar to CGRectZero so that, while hidden, it wouldn't effect layout geometry for a UIToolbar. Might you be manually editing the frame of one of the two tab bars you have?
I had this issue happen when I was trying to add a UITabBarController too soon. I was adding it as a child view controller of the main window.rootViewController in its viewDidLoad: method. However, the root view has not been properly initialized at this point yet, so the tab bar was using incorrect frame for calculations (as Ben Lachman alluded to). I solved it by adding a delay to initialize the images on the tab bar items, which in turn made the titles display with correct spacing.
I have a requirement for a very simple Button Bar.
It should take up the width of the screen.
It should allow at least 3
buttons.
The buttons should be of equal width and together take up
the whole width of the bar.
Each button should be tappable, but not
have a selected state.
The bar will be overlaid on a MapView and positioned directly above a TabBar.
Tapping a button will launch a Modal ViewController.
I thought about using a UITabBar and not allowing its tabs to become selected, but the HIG is pretty clear that this is not correct usage and UIToolBar doesn't allow the button widths to be set.
This seems like a very simple requirement but I can't see an obvious solution. Is there something I'm missing? Can anyone suggest a solution?
What's wrong with just creating a simple view that draws an appropriate gradient, and then adding three buttons of the appropriate size?
If you're feeling ambitious, or if this is something that you're likely to use more than once, you could even have the view create the three buttons. Call it ThreeButtonBar or something. Give it a constant height and adjust the width to match that of its superview so that you can use it in portrait or landscape orientation.