I made a vertical (in looks) toolbar programmatically. Using initWithFrame I set the width and height of the toolbar and sent it to extreme right.
Now I added a bar button item to the toolbar and set an action for it. But when I click anywhere on the toolbar, the action message is being sent. And I checked the sender, the sender is not the toolbar but the button.
I tried on another toolbar which I placed horizontally, the buttons are seen as tapped if I click in the vicinity of the button. And since now my toolber is vertical (but horizontal according to iOS), clicking anywhere on the toolbar calls the function.
I want to send the message only when I click on the button and not on the toolbar.
I want to use the camera icon provided by apple, so I am not in favor of using UIButton. (I can set a custom image, but it would be good if i can avoid that)
I also think that placing a horizontal toolbar and using CGAffineTransform can solve the problem. But it would be nice if there is clean method.
Using the transform is definitely the way to go.
Run the identity transform through this function and set it as the transform on your bar. I think it is a very simple solution.
It shouldn't be hard to set the transform right after you init with a normal frame. To avoid stretching you can make that frame using the values you are already using but swapping the x and y.
I don't believe that UIToolbar supports vertical orientation; you'll probably be better off rolling your own toolbar-like control.
Related
I have my swift 5 app working and I'm now adding a 'tool tips' feature, explaining what each part of the screen does.
The approach I have taken is from an article online - add a subview of grey to dim the background, then to that, add a subview of the item being described again, so it is now highlighted, then also, add a subview of an explainer bubble to explain the item highlighted.
This works fine, so long as the UIView I'm using isn't from a UIBarButtonItem. When it is, the bar buttons underneath the grey screen move around to accomodate what they believe is another bar button being added, which causes everything to miss-align. Other buttons do not have this problem, only UIBarButtons.
Any advice is greatly appreciated. Thanks.
Are you adding the duplicate subview to the bar itself? It'd probably be better to add it to the screen rather than the bar so it doesn't affect the bar's layout. In order to get its frame relative to the view controller so you can display your duplicate in the correct position, you could use:
barButtonItem.convert(barButtonItem.bounds, to: self.view)
Assuming self is a UIViewController.
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.
So I have a custom nav bar in my iPad app which is a bit larger than the default 44 pixel bar (52 pixels tall). I want all the items in the nav bar to be center aligned which I have been able to do just fine with the exception of one item, the back button. I don't want to use a custom back button and instead just use the default one and just nudge its position down a bit so that its aligned with the center of my navbar. I haven't been able to find a clear answer to this and am not sure if its even possible. Anybody done something like this?
http://cl.ly/image/0g3f2M260B3C
UPDATE :
This can be done and I found the answer here : UIBarButtonItem Offset?
Ok well,but we can't change the custom back button position so try to implement that one also by custom.
By default back button position was center so we can't change that position.
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.
I need to have an iPad app that has a consistent toolbar at the top of the screen. I need it to adjust when switch from landscape to portrait. Essentially what I need is something that acts like a UINavigationController, but allows me to have an arbitrary number of buttons like a UIToolbar. I've seen this done, but I can't figure out how to do it.
Thanks
There is no reason you can't just use a standard UIToolbar at the top of the screen, rather than the bottom. This allows you to add as many buttons as you can squeeze on, and customise their appearance.
In order that it should adjust its size when switching interface orientation, you simply need to adjust its autoresizingMask property. This is easy in Interface Builder - just turn on the horizontal arrow in the middle of the autoresizing box (this makes the width flexible), and maybe make sure that the left, right and top struts are enabled to so as to hold it in the correct position.