Back button is not visible in iOS 7 - uinavigationbar

I have some weird trouble about iOS 7. I have an UINavigationBar in my app and it works perfect for iOS 6;
-- IOS 6 --
However, when i try to run it on iOS 7, my back button disappeared. It's there, still working and clickable but not visible;
-- IOS 7 --
How can I fix this problem ?

Setting BackButtonBackgroundImage via UIAppearance currently has some odd behavior in iOS 7. This is probably related to the updated design, which replaces the rect-style button with a backIndicatorImage (an arrow).
This leaves 3 options for customizing the back button's appearance:
Change the color of the backIndicatorImage by setting the tintColor property on UINavigationBar (or one of its superclasses).
Set the new backIndicatorImage property on UINavigationBar to a custom image. (don't forget to set the backIndicatorTransitionMaskImage as well or it won't work)
Create a custom UIBarButtonItem and manually assign it as UINavigationItem's leftBarButtonItem. (See the answer mentioned above by Mashhadi)

By the way, if you have to keep support ios 6 version like me, use that;
if (floor(NSFoundationVersionNumber) <= NSFoundationVersionNumber_iOS_6_1)
{
// My iOS 6 back button background
self.navigationController.navigationBar.tintColor = [UIColor colorWithRed:39.0f/255.0f green:184.0f/255.0f blue:199.0f/255.0f alpha:1.0];
}
else
{
self.navigationController.navigationBar.tintColor = [UIColor whiteColor];
}

I used Wes Dearborn's answer and implemented a nice way of supporting both iOS5+'s back button and iOS7's backIndicatorImage:
Back button strangely disappearing in UINavigationController but keeps working

Related

setTitleTextAttributes not working after view on screen. iOS 11

I've spent a whole day trying to change the colour of a UIBarButtonItem and now i'm thinking it is an iOS 11 bug unless someone can tell me it's by design.
I can change the colour of the text by using this code
[self.refreshButton setTitleTextAttributes:#{NSForegroundColorAttributeName: [UIColor orangeColor]} forState:UIControlStateNormal];
If I add the code to the viewWillAppear:animated function it works fine, however if you add it to viewDidAppear:animated it does not work.
It seems to work on the iOS 9 simulator, but not iOS 11.
Has something changed in this regard in iOS 11?
If all you want to do is change the title color of your UIBarButtonItem you can set the tintColor property instead of setTitleTextAttributes:. If you want all of your UIBarButtonItems to have the same title color you can set the tintColor of your tool/navigation bar.
I had the same issue on iOS11 but needed to set the font by setTitleTextAttributes. Unfortunately this does also not work by appearance. The only solution I found was to create new BarButtonItems as copy of the old ones and then set them as navigationItem.rightBarButtonItems.
For reference for other users having the same issue.
This Stack Overflow answer may explain why the method doesn't work.
An improper setting of UIControlState() may be the problem.

iOS 7 keyboard issue

I am using iOS 7 for my application. In my app I have changed keyboard appearance to 'UIkeyboardApperanceAlert'. It makes keyboard black. But problem is when app comes from background to foreground, whenever I click in textField it first opens keyboard with white color and then it's color turns to black.
Why this is happening?
I found that setting autocorrectionType property to UITextAutocorrectionTypeNo resolves this issue!
self.myTextField.autocorrectionType = UITextAutocorrectionTypeNo;
UIKeyboardAppearanceAlert is Deprecated in ios7. Use UIKeyboardAppearanceDark instead.
This is a bug in iOS 7, I had feedback on Apple dev forums.
iOS 7 Keyboard color flash
Try this:
Declare the textField in your h. file.
On your viewDidLoad / viewDidAppear add this (after allocating and initializing ofcourse):
[(UITextField *)yourSubView setKeyboardAppearance:UIKeyboardAppearanceAlert];
Or
[yourTextField setKeyboardAppearance:UIKeyboardAppearanceAlert];

IOS 7 Button Background Does Not Work

I have a project that comes from IOS6, and now with the button changes of the IOS7 I had to make a background to my project buttons. Although, when I try to set a background image for my buttons it doesn't work! programming or not it doesn't work!
I tryied:
[buttonOutlet setBackgroundImage:[UIImage imageNamed:#"lineStyleScreen.png"] forState:UIControlStateNormal];
and the IDE! BOTH DONT WORK!!!
I wonder if it is because I did't updated my storyboard to IOS7.
ios 7 doesnt support regular ios 6 buttons. Do follow this link:
http://dev.iachieved.it/iachievedit/?p=127
Is the button type set to Custom in properties inspector?
Try to set the tint color to the button for iOS 7
button.tintColor = [UIColor greenColor];
Note:- set the tint color that will suit to your requirement

Views converted to ios7 flow under navigation/bottom bars in ios6

I have an app that uses stroryboards, a navigation controller and autolayout that runs fine under io6 and I would like to enable to run under both ios6 and ios7.
I have converted the app using xcode5 and it now runs fine under ios7, but when I run it under ios 6 the navigation bar and bottom bar are now transparent (they were not originally) and the view flows under them - hiding some of the controls. This persists even if I convert the ios7 app not to flow under these bars (by setting Extend Edges / Under Top Bars and Under Bottom Bars OFF).
I have worked around it by allowing ios7 to flow the view under the bars (what Apple wants us to do anyway) and then adding the following code to the viewDidLoad method of the fist view controller to force ios6 not to use transparent bars.
if (floor(NSFoundationVersionNumber) <= NSFoundationVersionNumber_iOS_6_1) {
self.navigationController.navigationBar.barStyle = UIBarStyleBlackOpaque;
self.navigationController.toolbar.barStyle = UIBarStyleBlackOpaque;
}
This seems to be working, but I don't understand why I need to do this and I am concerned that I am missing something fundamental.
Edit: The other concern I have with this 'solution' is that the Preview in xcode5 under ios6 doesn't accurately reflect the layout as it runs under a simulator under ios 6 (I don;t have a real ios6 device handy to test it at the moment). The new preview feature in xcode5 appears to assume that the ios 6 will not flow the view under the top and bottom bars and thus squashes the controls together to fit into the available space.
Ali
Try this regardless of the OS version (it solved me a similar issue recently):
self.navigationController.navigationBar.translucent = NO;
self.navigationController.toolbar.translucent = NO;
I am not sure if this will help you, but there is another option to your situation: try using the __IPHONE_6_1 macro. I have an example:
if(__IPHONE_7_0) {
NSLog(#"Hello");
}
so you could just do
if(__IPHONE_OS_VERSION_MAX_ALLOWED <= __IPHONE_6_1) {
self.navigationController.navigationBar.translucent = NO;
self.navigationController.toolbar.translucent = NO;
}
hope this helps you

Use iOS 6 Style Segmented Control in iOS 7?

Is it possible to have a segmented control on an iOS 7 device show up as the iOS 6 version of the control?
We really aren't ready for an interface redesign and the new flat control doesn't jive with the rest of our UI. It would definitely be best to keep the iOS 6 style for now, if possible.
To clarify, I am compiling using the iOS 6.1 Base SDK. I am aware that this is the "obvious" answer to my question, but it does not work. Most other UI elements will show up with iOS 6 styling by doing this, but like the UIAlertView and UIActionSheet, the UISegmentedControl does not. However, unlike the UIAlertView and UIActionSheet, UISegmentedControls do not feel like a "system" item; they should be able to display in iOS 6 mode.
Edit: I thought it would be helpful if I finally included a picture with this (probably should have done this from the start). However, the answer I provided did fix the issue. Also, in retrospect, it looks like this might be the iOS 6 style after all, it's just displaying so wrong that it appears like iOS 7 style.
I manage to do a pretty good job of solving this problem by setting all the attributes manually, but it is not quite perfect.
This is what I ended up doing:
- (void)fixSegmentedControlForiOS7
{
NSInteger deviceVersion = [[UIDevice currentDevice] systemVersion].integerValue;
if(deviceVersion < 7) // If this is not an iOS 7 device, we do not need to perform these customizations.
return;
NSDictionary *attributes = [NSDictionary dictionaryWithObjectsAndKeys:
[UIFont boldSystemFontOfSize:12], UITextAttributeFont,
[UIColor whiteColor], UITextAttributeTextColor,
nil];
[self.segmentedControl setTitleTextAttributes:attributes forState:UIControlStateNormal];
NSDictionary *highlightedAttributes = [NSDictionary dictionaryWithObject:[UIColor whiteColor] forKey:UITextAttributeTextColor];
[self.segmentedControl setTitleTextAttributes:highlightedAttributes forState:UIControlStateHighlighted];
self.segmentedControl.segmentedControlStyle = UISegmentedControlStyleBar;
self.segmentedControl.tintColor = [UIColor colorWithRed:49.0 / 256.0 green:148.0 / 256.0 blue:208.0 / 256.0 alpha:1];
}
To fix images assigned with InterfaceBuilder use this code:
- (void)fixImagesOfSegmentedControlForiOS7
{
NSInteger deviceVersion = [[UIDevice currentDevice] systemVersion].integerValue;
if(deviceVersion < 7) // If this is not an iOS 7 device, we do not need to perform these customizations.
return;
for(int i=0;i<toSegmentedControl.numberOfSegments;i++)
{
UIImage* img = [toSegmentedControl imageForSegmentAtIndex:i];
UIImage* goodImg = [img imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
// clone image with different rendering mode
[toSegmentedControl setImage:goodImg forSegmentAtIndex:i];
}
}
I just ran into this problem today myself. The app I'm working on updating is quite old, and still uses xib files, so I do not know if this works on storyboards or not. As others suggested above, you still need to use the iOS 6.1 SDK, but this alone is not enough. After performing the following steps, I was able to get the old UISegmentedControl appearance back:
Open the interface builder document in question
Go to the file inspector (first inspector tab; has a document icon)
Under the "Interface Builder Document" section, change "Opens in" to Xcode 4.6
I do believe this is a bug, and I would not be surprised if there isn't a workaround for UISegmentedControl instances created in code. I'm guessing this is somewhat related to the deprecation of the segmentedControlStyle property in iOS 7 (see https://developer.apple.com/library/ios/documentation/uikit/reference/UISegmentedControl_Class/DeprecationAppendix/AppendixADeprecatedAPI.html#//apple_ref/occ/instp/UISegmentedControl/segmentedControlStyle).
Hope this helps someone out there.
If you save the iPhoneOS6.1.sdk file from the previous version of XCode and add it to Xcode 5 in the same path you can then build an app against the 6.1 SDK so that when it runs on 7 everything is like 6. Linking against iOS7 SDK tells iOS to make everything look like iOS7 if possible. Essentially then you have an iOS6 app but building it with XCode 5.
If you use images on any of your UISegmentedControl segments, you'll need to add some code to set those properly on iOS 7, otherwise they'll be used as a template image and the selected segment will be a cutout of the segment's background.
UISegmentedControl under iOS 7 interprets its images as being in rendering mode UIImageRenderingModeAlwaysTemplate unless otherwise specified. I had to use -[UIImage imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] on each segment's image for iOS 7 to achieve the previous behavior.
Either you could:
Not update your app at all for iOS7 until you're ready to make some UI changes. Apps compiled against the iOS6 SDK will run in iOS6 Compatibility mode on iOS7 and will look exactly the same as they did in iOS6.
Apply custom background, separator, etc images to your segmented controls that mimic the look they had in iOS6.
Yes, it is possible if you recreate the control by your own. Create a fake segmented control that looks like and work like one.
In my app, I have set the Segmented control to "Bar" style. It renders in ios6 style on my ios7 iphone5 (whoa, 5,6,7). However, the text inside the segments are cut and have the three dots "..." added, no matter how wide the view is.
So the ios6 segmented control rendering in ios7 seems really buggy
Is it possible? Not really...
You could make your own custom segmented control.
Or you could use the UIAppearance proxy to customise your segmented control with images but then it's your responsibility to make it look like it was on iOS 6.

Resources