Background image of back button does not appear before it is touched iOS 7 - objective-c

I am experiencing some problems with [UIBarButtonItem appearance] for the the back button background image.
Normally (iOS 5 and iOS 6) I was able to set the background image of the back button like this:
[[UIBarButtonItem appearance] setBackButtonBackgroundImage:backButtonImage forState:UIControlStateNormal barMetrics:UIBarMetricsDefault];
But at iOS 7 the background image does not appear on the back button. The weird thing is, that the background image actually appears when the back button has been touched once.
I have tried setting the image for all states, to test if iOS 7 was using some kind of new state for an untouched back button, but that does not seem to be the case.
Do you have any idea, what I am doing wrong?

A solution which will make the background appear correctly on iOS7 is at OS 7 custom back button. It swizzles a method to fix the Apple bug (which is that they forget to call setNeedsDisplay on the private view when the background image is changed). Going borderless is probably better, if possible, but swizzling does work.

I searched for this problem and found that you are not the only one to have the same problem. There are many others who face the same issue with UIAppearance. These are the proofs (to explain you to your client) :
UIBackButton Background Image not appearing
Back button is not visible in iOS 7
In this case, what you can do is to follow the Answer provided in the 2nd Link.
You can either set the backIndicatorImage property on UINavigationBar to a custom image or you can change the color of the backIndicatorImage by setting the tintColor property on UINavigationBar.
You can create a custom UIBarButtonItem and manually assign it as UINavigationItem's leftBarButtonItem.

try to change the tint color of the button. There is some issue in iOS 7 for UIBarButton

I implemented a really nice solution that works under ios5+ here:
Back button item strangely disappearing under iOS7

To work with ios7 you need to use
UIImage *backButton = [[UIImage imageNamed:#"icon_back" resizableImageWithCapInsets:UIEdgeInsetsZero];
if ([UINavigationBar instancesRespondToSelector:#selector(setBackIndicatorImage:)]) {
[[UINavigationBar appearance] setBackIndicatorImage:backButton];
[[UINavigationBar appearance] setBackIndicatorTransitionMaskImage:backButton];
}else{
//ios 5 and 6 code
}

Related

QLPreviewController delegate method doesn't get called in iOS 10, but does get called if ran earlier than iOS 10

Here is my code. This may sound like redundant question but my scenario is different as I am not adding QLPreviewController as a subview but present as a controller.
After downloading from dropbox, I present it like-
self.pdfViewController = [[QLPreviewController alloc] init];
self.pdfViewController.delegate = self;
self.pdfViewController.dataSource = self;
[self presentViewController:self.pdfViewController animated:YES completion:nil];
and I also have QLPreviewControllerDataSource, QLPreviewControllerDelegate listed as the protocol. Besides, it is working if being run in earlier than iOS 10.0.
Please help me.
It looks like iOS 10 has changed the way that QLPreviewController is presented. On iOS 9 when I preview an image by presenting the QLPreviewController modally I see a nice zoom effect and the initial state of the preview is with a black background and the navigation and toolbar hidden. I can tap the image to make the bars visible (which changes the background to white). Tapping again toggles the state.
On iOS 10 the same code results in the white background view appearing and the zoom animation being incorrect (it seems to appear from off the bottom of the screen).
I found that implementing this practically undocumented new data source method for iOS 10 fixed the issue:
- (UIView* _Nullable)previewController:(QLPreviewController *)controller
transitionViewForPreviewItem:(id <QLPreviewItem>)item
{
return [self.tableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:MIDPhotoImageRowIndex_Image inSection:MIDPhotoSectionIndex_Image]];
}
The view I return is the same view that previewController:frameForPreviewItem:inSourceView: is using as the reference for the original content's frame (i.e. the image view in my table cell).
The documentation for this delegate method at the time of writing just says "No overview available".
Implementing that method did mean that the previewController:frameForPreviewItem:inSourceView: is now called on iOS 10. I just wish there was a way to default to the original black background without navigation bars.

Iphone uibutton click feel

My problem is I have to change UIButton backgroundcolor on click and navigation controller move to next page.
I don't need to use NSTimer to show button effect.
I need to apply this effect for my application all buttons.
I can't able to make my next view controller to wait for show this effect.
If I understand what you're asking correctly, you want all buttons in your application to instantly change background colors upon a button click. You can do this using the UIButton's appearance.
In short, UIAppearance allows developers to easily keep visuals consistent throughout their applications. For more information on what it is and how to use it, click here.
Here's an example:
//Inside of an IBAction that a button clicks
[[UIButton appearance] setBackgroundColor:[UIColor redColor]];

On iOS7, bar button item icons vanished in input accessory view

Moving my app from iOS6.1 to iOS7, all the button that were visible under iOS6.1 in the toolbar I created for the Input Accessory View of the keyboard are not visible anymore (but still active).
I tried all combinations of [myBar setTranslucent:...] and [myBar setBarStyle:...] but no way to make these buttons visible again. They are defined as:
UIBarButtonItem *myButton =[[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:#"myImage.png"] style:UIBarButtonItemStylePlain target:self action:#selector(mySelector:)];
<-iOS 7.1
<-iOS 6.1
Any idea? Thanks!
I found the solution of my problem.
The method I used to remove the standard input accessory view of the uiwebview was the reason of this problem, it left some view displayed that prevented from seeing the new UIToolbar view. I used the one described here in Stackoverflow and it works.

iOS 7.1 Breaks UITabbar Images Selected State

Since updating to iOS 7.1, my tab bar images initialize as if they were all active, they are all highlighted on launch. Once I visit each tab, that tab image resets and displays correctly. Has anyone else seen this behavior? Suggestions for work around?
I rolled back my xcode to version 5.0, which the only old version i have and build the app using it. It works perfectly on iOS7.1 device now.
If you have the xcode version 5.0.2 that would be great also.
In my case, as I finally figured out, this issue was caused by setup of appearance protocol on UIView in my style controller which is called at startup.
I had been setting an overall tint color for UIView. It did not apply to the icons in iOS7.0 but that must have changed in 7.1.
My style code:
// Color for buttons and enabled controls
UIView *viewAppearance = [UIView appearance];
[viewAppearance setTintColor:overallTintColor];
I added this to fix:
[[UIView appearanceWhenContainedIn:[UITabBar class], nil] setTintColor:[UIColor darkGrayColor]];
darkGrayColor is not ideal, I just threw it in there for testing. I tried using nil, as I would like it to just go back to the default as it used to. Giving nil as a color did not have any effect. I suppose I will play with some color values until I get a close match.

UIButton not receiving touches when added to subview, but does when added to main view

Basically I have a main screen that comes up with a background image and three menu choices across the bottom of the screen. When I add these 4 components to the RootViewController's view, everything works fine., but if I do something like
_mainContainer = [[UIView alloc] init];
self.view = _mainContainer;
_firstScreen = [[UIView alloc] initWithFrame:self.view.frame];
"some code here setting up the subviews"
[buttonLeft addTarget:self action:#selector(startGame) forControlEvents:UIControlEventTouchUpInside];
[_firstScreen addSubview:mainMenuBackground];
[_firstScreen addSubview:buttonLeft];
[_firstScreen addSubview:buttonMid];
[_firstScreen addSubview:buttonRight];
[_mainContainer addSubview:_firstScreen];
Essentially if I add everything directly to _mainContainer, the buttons work, if I add it to _firstScreen, then add _firstScreen they don't work.
User interaction is enabled on _firstScreen. I do something similar later in my app and it works fine. Also, not sure if this has anything to do with it, but despite my screen being displayed in landscape, and all options in the plist being set to landscape only, when I run a transition, like flipFromBottom (or whatever its called), my app thinks the "bottom" is with the screen being in portrait until I move to another group of subviews in my app. (So basically the title screen is acting screwy).
I looked everywhere for a solution, hopefully I am not missing something basic.
Hey what is mainMenuBackground?, if its a image , their is no need to make it as a subView, instead, the correct way is to set it as a background image. I hope this will solve your problem