What is the correct approach for a custom UIToolBar? - ios

Is it better - better in the sense of not getting rejected from the Apple store - when trying to create a custom* UIToolbar to either:
Option A
Add the oversize middle button as a UIButton to the self.navigationController.view this is key as I'm adding a UIButton to the navigationController which seems to contradict the apple docs
Use UIToolbar appearance to implement the custom background
Option B
Create a UIToolbar and add it as a subview of the current ViewController in UINavigationController
Add the UIButton as a subview of the current ViewController in UINavigationController
Use UIToolBar's method setBackgroundImage to add the custom background
*Custom background, Oversized middle button
This is the shape of the toolbar:
Extra details: This app is for iOS 5.X or greater. It uses UINavigationController. Key challenge is that a section of the app hide/shows the navigationbar depending on the state of the app.
Option A means I don't have to workout where to place the UIToolBar, it's a challenge to work out where to place the UIToolbar because a) if I'm showing or hiding the navigationBar this shifts everything up/down vertically b) iPhone 5 with extra vertical space - I can't use autolayout as I'm support iOS 5 and I haven't really worked out how to use autoresizing masks. I'mu using hard coded "magic" numbers.

I wouldn't do either of those.
UIToolbar is nice when you want to do what it does, and it does allow some basic customization. But in this case you want a toolbar-like view that draws itself in a way that UIToolbar doesn't seem to allow for. You probably know exactly what items you want to appear in your "toolbar", and it's unlikely that you'll need to handle arbitrary assortments of UIBarItems.
So, instead of giving yourself a headache trying to force UIToolbar to do something that it was never designed for, just create a simple view containing your background image (part of which will be transparent). Place some image-based UIButtons in the view, and call it a day. It wouldn't be a bad idea to create a custom UIView subclass representing your toolbar so that all the setup is nicely packaged up in one place, and so that you can reuse the toolbar in multiple views if you need to.

Related

Custom Keyboard Accessory view input

I have created a custom accessory view to supplement the standard Apple alpha iOS keyboard.
The purpose is to add a line of numeric keys to prevent flipping back and forth between keyboard views. At first, I created a toolbar and loaded it with a set of 0 - 9 titled buttonItems and it functioned quite well. However, it looked terrible, not at all like the alpha keys despite adding a rounded rect background image to each key because the system apparently prevents customizing font size and button spacing inside the stack view of the toolbar. Therefore, I created a UIView xib and loaded it with a stackView full of customized numerical buttons. When I add the UIView as the accessory view it looks pretty darn close to the rest of the Apple Alpha keyboard. The issue now is that the touch-up events go to the UIView class of the accessory view. Is there a clever, efficient way to have the button presses in the accessory emulate the std keyboard feeding into TextField: shouldChangeCharactersIn? I could package the button presses into a local notification event to get it into the class holding the textField but that seems terribly inelegant! Any suggestions would be greatly appreciated. Stay Safe!
Not the best answer, but I did implement notification on key button press with an observer in the main view class. The observer does a TextField.insertText which is suboptimal since I will need to refactor the several hundred lines of code that performs real-time language translation in the shouldChangeCharacters methods. Ah well.

Place image on top of all "layers" on iOS screen

What are the constraints/alternatives to place an image that stays on top of all iOS "layers" and windows. Think of it as a lock screen but that still allows you to interact with you phone, meaning browse, answer calls, etc. The image will be displayed in a transparent way (say 40%) and will be launched by an application.
Not really sure what you are asking for but if you are looking for a way to add some code once and it shows everywhere on each of your ViewController then there really is no way to do that.
What you can do is
Use UIToolBar
add buttons to that tool bar
Add that tool bar to each ViewController in storyboard (where you need them)
Create a global function / method that you can call in from any ViewController that has the button actions in it. That way you edit the code once in one place and use it every where.
If you don't like UIToolBar then
you can add your own UIImageView and add a transparent background to it
Add your buttons on the UIImageView. (You will have to add constraints)
then show that on every ViewController
If all this seems to much work then you can use existing controls HERE and see which one fits your needs.
This maybe a good one - FCVerticalMenu

iOS map style config slide up?

iOS 7 has changed how maps are displayed by apps on the iPhone, and especially how the user configures the map.
The map is displayed like this, with an Info button.
When the user taps the Info button, the configuration screen slides up.
How do I recreate a screen overlay like this in my code? While I don't want the user to be dropping pins, I want the user to be able to switch between different map styles or open the address I'm pointing to in Apple's Maps app.
If you are trying to do a simple overlay view, then look into making an UIView slide up through UIView animations. Other than that, you would need an UISegmentedControl and related code. You would also need to blur the view and make it translucent, so look into my other question and answer on how to properly blur an UIView:How to apply blur to a UIView?
I've never looked into it, but I've heard the only easy way to do a translucent background (as in, without writing your own OpenGL code) is to create a UIToolbar instance.
I'm guessing you'd make a toolbar with no items, just treat it like UIView and add your own subviews (UITableView, etc). It is a subclass of UIView.

Changing UIToolBar (appearance) at runtime

I want to change an UIToolBar at runtime. In it's initial state, is has only one button, when that button is pressed i want it to change it's appearance to show 4 buttons. One of these buttons should cause the first UIToolBar to reappear.
Im seeing two approaches:
1) Have two UIToolBar nibs, and load them as needed.
2) Having all buttons on the first UIToolbar, and hide/show them as needed.
What would be the correct approach?
Personally, I would want to see all 4 button at initial launch with only relevant button in enabled state and rest in disabled state. Once I tap on the already enabled button I should see other buttons getting enabled. This is less surprising UI for end user. However, you can also go with #2 mentioned above in which case you might want to add some animation effect for better user experience.
The second approach would be better, because if you want to add more buttons tomorrow, you need to maintain 2 nib files instead of one.
But, think again is creating toolbar in xib file good solution?
I would create custom toolbar extending UIToolbar class and make 2 methods in it:
-(NSArray*) toolbarButtonsInitial;
-(NSArray*) toolbarButtonsExtended;
-toolbarButtonsInitial method returns UIBarButtonItems for initial state
-toolbarButtonsExtended method returns UIBarButtonItems for second state.
IMHO, this way has several advantages:
Your xib file doesn't have hidden buttons, or some button above other
one
If you need to add or remove some buttons you can do that easily for
each state
You can easily reuse this toolbar on other screens and create new
states if necessary

How can I create a dynamic overlay for a UIButton?

My application has a few portions that have really big buttons (640x130, 230x150, etc.) What I need is to have a way to update different portions of the button, with different text. Initially, I assumed that in my code I could create various UILabels and then add them as subviews to my button. However, as soon as I try to add a UILabel to the button as a sub-view, my app crashes.
What is the easiest way to create an overlay for a button, that I can completely layout myself, without preventing button taps from being interested using overlay controls?
I imagine there are multiple ways to solve this problem. However, the best solution for my case should use the fewest lines of code (I have quite a few of these types of buttons) and I'd like to be able to continue using some form of configurable button within IB.
I'm not opposed to subclassing UIButton but, if I do, I would like to be able to use it in IB. I've never created a custom UIView for such a circumstance, so I'd need help defining that type of subclass so that it will work correctly in IB.
You need to add the subview to the containing view - not the button. To ensure that is doesn't interfere with button presses, be sure to set it to:
[myCustomTextOverlay setUserInteractionEnabled:NO];

Resources