Why my Bar Button item isn't getting hidden? - ios

I'm using UIBarButtonItem in my project. I've tried to hide the UIBarButtonItem in iOS 6.1, but I was unable to do the same using the following code:
barbuttonname.tintColor = [UIColor clearColor];
barbuttonname.enabled = NO;
This code hides the UIBarButtonItem in iOS 7.1, but in iOS 6.0 it shows the UIBarButtonItem. How can this issue be fixed?

The reason is because use of tintColor for that purpose only became available in iOS 7. in iOS 6, the buttons also typically have borders and backgrounds and each bit is handled separately. In terms of what you're actually trying to accomplish here, I think you should go about it a different way.
Instead of modifying properties on the button to hide it, simply remove it from the navigation bar or wherever you have it. For example, if it is the right button on a UINavigationBar, you would just do:
myNavigationBar.rightBarButtonItem = nil;
Then, when you want to show it again
myNavigationBar.rightBarButtonItem = myButtonItem;

Related

iOS 11 SearchDisplayController shows black status bar

I know SearchDisplayController is deprecated, but Storyboard still supports it, and it is an easy way to present tableViewController on top of your view controller. I have been using it, and I would still prefer to use that. And in iOS 11, when I run my app, the status bar of the SearchDisplayController. after the search bar is focused, is pitch BLACK. Does anyone know how to solve this bug? Also if you realize, the margins of the searcher is off. I am using the default iOS 11 searchbar. Below is attached screenshot:
Have you tried to set the extendedLayoutIncludesOpaqueBars property to true?
searchDisplayController.extendedLayoutIncludesOpaqueBars = true
This is not the best solution actually, but It works to change status bar color.
if let statusBar = UIApplication.shared.value(forKeyPath: "statusBarWindow.statusBar") as? UIView {
statusBar.backgroundColor = //YOUR COLOR HERE
}
Keep in mind this will affect the whole app. If you need to change some views only then save the previous color to restore it.
Regards.

How to hide Toolbar in newer iOS?

I upgraded an older version(ios6) of a tabbed based app to latest iOS. The app uses my own customkeyboard like showing in the image attached. The tabbar supposed to stay on top of the keyboard, but with new iOS versions, I get this new toolbar by default. How do I get rid of this bar because it's sitting on top of my tabbar?
UITextInputAssistantItem* item = [textField inputAssistantItem];
item.leadingBarButtonGroups = #[];
item.trailingBarButtonGroups = #[];
The thing on the top is a suggestion list.
I just tested this in Xcode. The way to hide is to disable auto-correction. Do it programmatically or using storyboard by highlighting search bar.
searchBar.autocorrectionType = UITextAutocorrectionTypeNo;

How to change color of the buttons within UIImagePickerController when taking a photo?

For iOS 7 and iOS 8, I'm trying to to change the button color to transparent for the front/back, cancel, and camera button within a UIImagePickerController view. I've tried setting the tintColor, navigationBar tint color, and some appearance settings.
Here's my best guess of how to do it - using Xamarin/Monotouch but an answer in native code works fine:
UIButton.AppearanceWhenContainedIn (typeof(UIImagePickerController)).TintColor = UIColor.Clear;
I've also tried changing the navigation bar options:
var imagePicker = new UIImagePickerController();
imagePicker.NavigationBar.BarStyle = UIBarStyle.Black;
imagePicker.NavigationBar.BarTintColor = UIColor.Orange;
imagePicker.NavigationBar.Translucent = true;
imagePicker.NavigationBar.TintColor = UIColor.Blue;
No effect. Here's an example of it not working. (trying to make the green areas transparent)
What's the best way to make the background of the buttons transparent? Thanks!
UIAppearance isn't going to work right for you on UIImagePickerController (at least as of iOS 8.1). Same goes for a lot of built-in controllers, like the email one, etc.
In order to do what you need, there is an option to completely replace the UI on the camera. Then you can style it however you wish. Basically set ShowsCameraControls to false and add your own views, there are methods for changing the flash and starting the camera you can call programmatically.
It's definitely more work, but probably your only option.

uiappearance for UIButton also changes UIBarButton image?

I am using this piece of code
[[UIButton appearance] setBackgroundImage:[UIImage imageNamed:#"button.png"] forState:UIControlStateNormal];
To change the appearance of UIButtons. This works nicely and does not affect UIBarButtonItems except for one of them (The only one that is not an auto generated "back" button) and only initially. When you touch the barbutton, it reverts back to not having a background image.
The problematic button is a UIBarButton and not an UIButton (Unless it is both, in which case the other UIBarButtons should be affected too).
A clue can be that the other UIBarButton that are not affected are all generated and not created by me in the storyboard.
This must be a bug in the api?
Solved using setTintColor. Was an api bug that since then probably has been fixed

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