Custom UIBarButtonItem/UISegmentedControl for UINavigationController - ios

Currently I would like to make my UINavigationController have the look and feel like facebook's main view.
I was thinking about using a UIsegmentedControl which would have a transparent background with an image inputted into the button's view.
Another idea was creating custom buttons with their background image as an image.
If anyone has any ideas on how this is done or an example project I can refer to, please REFER me!!! Haha.
Thank you stackoverflow!!!

in this case i would just use standard UIBarButtonItems for the left and right ones.
The center would then be a custom view with 3 buttons inside.
UINavigationItem has a property called 'titleView'.
So in some appropriate controller just do s.th. like:
self.navigationItem.titleView = myCustomViewWithThreeButtonsAsSubviews;
self.navigationItem.rightBarButtonItem = myLeftUIBarButtonItem;
self.navigationItem.leftBarButtonItem = myRightUIBarButtonItem;
setting the styles of the barButtontem to UIBarButtonItemStylePlain and providing images will do the job easily.

Related

iOS SideMenu Background Image not displaying correctly

I have setup my project to mimic the SideMenu example project to the best of my abilities, but the background image for the sideview is
not displaying properly. I would like to only have underlines under the cells that I setup, not have a title bar and have the background image stretched across the sidemenu, not repeated several times. I am fairly weak on storyboarding, so if there is any info you need to help with this, please let me know. I have gone through all of the attributes settings I could and can't seem to find anything else helpful.
I have included a picture of the look I want to achieve, my current app and my current tableview in the storyboard interface
Below is my code showing how I am setting up the side menu background image.
SideMenuManager.default.menuLeftNavigationController = storyboard!.instantiateViewController(withIdentifier: "LeftMenuNavigationController") as? UISideMenuNavigationController
SideMenuManager.default.menuAnimationBackgroundColor = UIColor(patternImage: UIImage(named: "sidemenubackground")!)
// Enable gestures. The left and/or right menus must be set up above for these to work.
// Note that these continue to work on the Navigation Controller independent of the View Controller it displays!
SideMenuManager.default.menuAddPanGestureToPresent(toView: self.navigationController!.navigationBar)
SideMenuManager.default.menuAddScreenEdgePanGesturesToPresent(toView: self.navigationController!.view)
I am trying to achieve this look. My current view repeats the background image repeatedly, has a title bar on the top and has underlines under nonexistent cells:
This is what my side menu looks like currently:
Here is what my tableview looks like in the storyboard currently:

iOS) How to add a divider(==separator) between tabbarItems

I searched this question many times but couldn't get enough information.
So I will use UIButton or UIView to replace UITabbar for customizing issue.
I want to put divider(separator) between two tabbarItems and bottom lines like the image below
But What I made now is below:
How can I make it as I want?
I did customize many view components(UIViewcontroller, UIButton, UITextfiled,UITableViewCell,UICollectionViewCell) but I don't know how to customize tabbarItem
I'm afraid there is no specific option to set a divider in UITabBar. But you can always use a custom tab bar. You can check this out, it has a special property for seperator image:
NMBottomTabBarController for iOS
There is also another option. You may like this :) I also used it myself in one of my app. I made an image that looks like a tab bar with seperator as a background image. Then put the items on it. Easy peasy. For example check this image:
Image Link
I hope this helps.

IOS: How to send an Image View back and front

In my storyboard I have a view on which I have an ImageView and a Button. The ImageView is currently covering my button and I would like to put the button over the ImageView. I found similar topics which were solved by going to "Editor" -> "Arrange" -> "Send to Front", however that was done for UIViews and this option is passive for ImageView and Buttons.
So how can I send my ImageView to background? Is the best solution for this to add an additional view only for the Button and then bring it to front?
You can rearrange your views on storyboard:
First view in order will be hidden by next view.
Maybe this options will be also useful for your running application:
myImageView.layer.zPosition = -5;
myImageView.layer.zPosition = 5;
Like in HTML/CSS.
The solution was to move the view components up and down in the "Document Outline" section.
Alternatively, you could've solved the problem using the bringSubviewToFront function:
[self.view bringSubviewToFront:self.yourButtonControl];

What is the correct approach for a custom UIToolBar?

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.

iOS Can't change UIBarButtonItem image properly

I'm having a problem when I try to change a UINavigationBar's "back" button custom icon. To achieve such a thing, I'm using the following code:
- (void)viewDidLoad {
[super viewDidLoad];
UIBarButtonItem* leftBtn;
UIImage* botonVolverImg = [UIImage imageNamed:#"boton_volver.png"];
leftBtn = self.navigationItem.leftBarButtonItem;
leftBtn.image = botonVolverImg;
}
But, when the view appears, you see this:
a busy cat http://www.timotteo.com.ar/boton.png
(You can see that the old button still appears at the back, plus the image I chose looks a bit streched)
I've been changing the imageInsets property, but that doesn't seem to work. I've also been reading the forum around, but couldnĀ“t find the exact solution.
Any suggestions are welcomed!
The image property for UIBarButtonItem doesn't correspond to the background image, only an image that provides additional context. If you're targeting 5.0+, your best bet would be to use -setBackButtonBackgroundImage:forState:barMetrics: to set a background for the bar button item.
To supplement Mark's answer, if your customer is requiring you to support iOS 4, you could create a UIButton that looks exactly how your customer wants it to (ie, just that image), and then use UIBarButton's initWithCustomView method to create your own back button. You can then have that button trigger popViewController or whatever appropriate action you need.

Resources