IOS 8 - Navigation bar buttons issue - ios

My app has simple viewControll(XIB, no storyboard) with 6 sub views
When user click on buttons sub view bring in front of current view (by using call [self.view bringSubviewToFront:usageView];)
App working fine on IOS 6 and 7 but I facing issue on IOS 8.
When I click on buttons for bring sub view in front sub view come up with like below image
Navigation bar right side buttons "Done" show improper, its hide only in iOS 8
Please help me for this issue I am new in IOS development. If your required any more information please comment.

Add this in viewDidLoad method of this viewController and customise it like you want
UIImage *backButtonImage = [UIImage imageNamed:#"Back_A.png"];
UIImage *backButtonImage1 = [UIImage imageNamed:#"Back_B.png"];
UIButton *backButton = [UIButton buttonWithType:UIButtonTypeCustom];
[backButton setImage:backButtonImage
forState:UIControlStateNormal];
[backButton setImage:backButtonImage1
forState:UIControlStateSelected];
[backButton setImage:backButtonImage1
forState:UIControlStateHighlighted];
backButton.frame = CGRectMake(0, 0, 55, 45);
[backButton addTarget:self
action:#selector(goBack)
forControlEvents:UIControlEventTouchUpInside];
UIBarButtonItem *backBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:backButton];
self.navigationItem.rightBarButtonItem = backBarButtonItem;
With frame you can show the button where you want.

Related

Interface Builder adjusting navigation item incorrectly

I have been messing with this for a while and I can't figure out what would be causing this issue. I have a UIViewController embedded in a UINavigationController and on the generated UIViewController has two UINavigationItems:
1:left button is a default Done button with no image - appears fine
2:right button is a plain button with a 30x30 image
These buttons are not connected to any IBOutlet and are not altered within the Swift code. However when the code is compiled and is running on a simulator the right button is pushed down the screen. If the image is removed and standard text is added the button appears fine.
Any suggestions would be greatly appreciated, thank you
Environment details:
MacOSX 10.11.2 , Xcode 7.2
This is what I do in objective-c to set the buttons to a specific side.
UIImage *image = [UIImage imageNamed:#"Notification.png"];
UIButton *button = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 40, 40)];
[button setBackgroundImage:image forState:UIControlStateNormal];
[button addTarget:self
action:#selector(goToNotifiationView:)
forControlEvents:UIControlEventTouchUpInside];
button.adjustsImageWhenHighlighted = NO;
UIBarButtonItem *rightButton =
[[UIBarButtonItem alloc] initWithCustomView:button];
self.navigationItem.rightBarButtonItem = rightButton;

UINavigationBar barButtonItem change back button image and title

Is it possible to change the back button on a UINavigationBar and change the title?
When I try to set the customView property, I get an image right next to the default button.
I use this code
self.navigationItem.backBarButtonItem = [[UIBarButtonItem alloc] initWithImage:backButtonImage landscapeImagePhone:nil style:UIBarButtonItemStylePlain target:nil action:nil];
I want the title to be "Back" which is easy enough to do in Storyboard. But the problem is that no matter if I use code above or use customView property, the default back button remains.
You can add a UIImage to the UIButton. And, then use it as a custom back button. Here's a quick example:
// Custom image
UIImage *backButtonImage = [UIImage imageNamed:#"button-background-image.png"];
UIButton *backButton = [UIButton buttonWithType:UIButtonTypeCustom];
[backButton setFrame:CGRectMake(0, 0, 100, 30)];
[backButton setBackgroundImage:backButtonImage forState:UIControlStateNormal];
// Custom title
[backButton setTitle:#"Back" forState:UIControlStateNormal];
[backButton setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
[backButton addTarget:self action:#selector(barPayButtonPressed:) forControlEvents:UIControlEventTouchUpInside];
[backButton setShowsTouchWhenHighlighted:NO];
UIBarButtonItem *buttonOnBar =[[UIBarButtonItem alloc] initWithCustomView:backButton];
self.navigationItem.leftBarButtonItem = buttonOnBar;
Note: You will loose the chevron (system-provided back arrow) which was introduced in iOS7. It goes as a title and chevron together presenting your previous view controller.
Update:
You can also use UIEdgeInsets to resize your image intelligently.
UIEdgeInsets edgeInsets = UIEdgeInsetsMake(0, 0, 15, 10);
UIImage *backButtonImage = [[UIImage imageNamed:#"button-background-image.png"] resizableImageWithCapInsets:edgeInsets];
You can achieve what you want by setting the navigationItem.leftBarButtonItem of the view controller that's being pushed to the custom bar button item with the look you want. Good Luck!

Custom navigation bar back button with only image

I want to show custom navigation bar back button. I want to show only image on it. I want to use this button in whole app also dont want to create this button in each file. How can i??
Here is my code:
// Set the custom back button
UIImage *buttonImage = [UIImage imageNamed:#"back_arrow.png"];
//create the button and assign the image
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
[button setImage:buttonImage forState:UIControlStateNormal];
//set the frame of the button to the size of the image (see note below)
button.frame = CGRectMake(0, 0, buttonImage.size.width, buttonImage.size.height);
[button addTarget:self action:#selector(popViewControllerAnimated:) forControlEvents:UIControlEventTouchUpInside];
//create a UIBarButtonItem with the button as a custom view
UIBarButtonItem *customBarItem = [[UIBarButtonItem alloc] initWithCustomView:button];
self.navigationItem.leftBarButtonItem = customBarItem;
but this is showing on current page only.
Another code:
[[UIBarButtonItem appearance] setBackButtonBackgroundImage:[UIImage imageNamed:#"back_arrow.png"] forState:UIControlStateNormal barMetrics:UIBarMetricsDefault];
Using this code back button image is showing in whole app. But the text "Back" is also showing. How can i solve this problem.
Thanks in advance.
I've used a category in the past to do this.
Create a category on UIBarButtonItem called +projectButtons (or something).
Then you can have a function like...
+ (UIBarButtonItem)backArrowButtonWithTarget:(id)target action:(SEL)action
{
UIImage *buttonImage = [UIImage imageNamed:#"back_arrow.png"];
//create the button and assign the image
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
[button setImage:buttonImage forState:UIControlStateNormal];
//set the frame of the button to the size of the image (see note below)
button.frame = CGRectMake(0, 0, buttonImage.size.width, buttonImage.size.height);
[button addTarget:target action:action forControlEvents:UIControlEventTouchUpInside];
//create a UIBarButtonItem with the button as a custom view
UIBarButtonItem *customBarItem = [[UIBarButtonItem alloc] initWithCustomView:button];
return customBarItem;
}
Then add it to you navigation bar like so...
self.navigationItem.leftBarButtonItem = [UIBarButtonItem backArrowButtonWithTarget:self action:#selector(popViewControllerAnimated:)];
This means you only need one line of code to create it but you still get the customisation of the target and action in each VC that you use it in. If you decide to change the look of the button then it's all done in one place.

MFMailComposeViewController customize

I am customizing MFMailComposeViewController it is working fine in ios 5.0 and ios 5.1 but not working properly in ios 6. The custom send and cancel button does not appear in mailcontroller.
My code is :
sendBtn = mailer.navigationBar.topItem.rightBarButtonItem;
cancelBtn = mailer.navigationBar.topItem.leftBarButtonItem;
[[UINavigationBar appearance] setBackgroundImage:[UIImage imageNamed:#"navigation.png"] forBarMetrics:UIBarMetricsDefault];
UINavigationItem *mailVCNavItem = [mailer.navigationBar.items objectAtIndex:0];
// Get the old bar button item to fetch the action and target.
UIBarButtonItem *oldCancelBarButton = [mailVCNavItem leftBarButtonItem];
// Create your new custom bar button item.
// In my case I have UIButton with image set as a custom view within a bar button item.
UIButton *backButton = [UIButton buttonWithType:UIButtonTypeCustom];
[backButton setImage:[UIImage imageNamed:#"cancel-button-hover.png"] forState:UIControlStateNormal];
[backButton addTarget:oldCancelBarButton.target action:oldCancelBarButton.action forControlEvents:UIControlEventTouchUpInside];
[backButton setFrame:CGRectMake(0, 0, 55, 28)];
self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:backButton];
UIButton *sendbtn = [UIButton buttonWithType:UIButtonTypeCustom];
[sendbtn setImage:[UIImage imageNamed:#"send-btnComment.png"] forState:UIControlStateNormal];
[sendbtn addTarget:self action:#selector(sendMail:) forControlEvents:UIControlEventTouchUpInside];
[sendbtn setFrame:CGRectMake(0, 0, 55, 28)];
self.navigationItem.rightBarButtonItem =[[UIBarButtonItem alloc] initWithCustomView:sendbtn];
MFMailComposeViewController and the related Facebook and Twitter sharing views are implemented through remote view controllers in iOS 6. This means that the controllers are run in another process and it is no longer possible to customize them by accessing their properties or subviews directly. You can still do so through UIAppearence though, but what you are trying to with replacing the buttons is no longer possible in iOS 6.

iOs: How to change color of "more" back button when having more than 5 tabs

I have an application with 6 tabs, so the system automatically generates the first 4 tabs and a fifth tab called "Altro" ("More" in italian) that contains the previous fifth and sixth tab content.
This is ok. The problem is that i don't know how to change the color of the back button when going through the "altro" tab. Any advice?
Some screenshot for a better explanation of the problem:
UIImage *buttonImage = [UIImage imageNamed:#"back_btn.png"];
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
[button setImage:buttonImage forState:UIControlStateNormal];
button.frame = CGRectMake(0, 0, buttonImage.size.width/2, buttonImage.size.height/2);
[button addTarget:self action:#selector(backPressed) forControlEvents:UIControlEventTouchUpInside];
UIBarButtonItem *customBarItem = [[UIBarButtonItem alloc] initWithCustomView:button];
self.navigationItem.leftBarButtonItem = customBarItem;
Try this.......once
You can change the color of backButton using the following code:
self.navigationItem.backBarButtonItem.tintColor = [UIColor redColor];

Resources