UITextfield UIDatePicker inputView very dark - ios

I have a UITextField that needs to show a UIDatePicker with a UIToolbar in above to close it.
I set the UIDatePicker to the textfield's inputView, and the UIToolbar to the inputAccessoryView.
This works fine, but by default i get weird color effects. The inputAccessoryView is translucent as one would expect from iOS7, however the inputView appears to have a black background behind it that is then made translucent. This leaves it with the inputView much grayer when the background color is set to the same as it is in the inputAccessoryView.
Here is my code:
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
UIDatePicker *datePicker = [[UIDatePicker alloc] init];
datePicker.backgroundColor = [UIColor clearColor];
[self.someTextField setInputView:datePicker];
UIToolbar *pickerToolbar = [[UIToolbar alloc] init];
pickerToolbar.backgroundColor = [UIColor clearColor];
UIBarButtonItem *doneButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:nil];
pickerToolbar.items = #[doneButton];
[pickerToolbar sizeToFit];
self.someTextField.inputAccessoryView = pickerToolbar;
}
This results in an image like this (with the main view's background colors set in InterfaceBuilder):
You can see the red and green showing through both, but the UIDatePicker is much darker.
If I change both from clearColor to whiteColor, I get this:
Here you can see the inputAccessoryView is still translucent (though less so), but the inputView is pure white. If it is translucent it is a LOT less, and I can't see it anymore.
How can i make them both transparent? As is, difficult without just making both entirely opaque. I want to keep them translucent to follow iOS7 guidelines, but not if it will give me that muddy dark version like in the first screenshot.

Related

Remove back button text and center title in navigation bar

I've removed the text for UIBarButton in AppDelegate:
[[UIBarButtonItem appearance] setBackButtonTitlePositionAdjustment:UIOffsetMake(0, -1000.f) forBarMetrics:UIBarMetricsDefault];
Which works like a charm:
As you can see, this doesn't align the navigation title at horizontal center. What is the best solution to accomplish this globally for all views.
PS: I am using Storyboard.
You can create your own custom titleView with a UILabel as follows:
UIView *titleView = [[UIView alloc]initWithFrame:CGRectMake(0,0,100,50)];
UILabel *titleLabel = [[UILabel alloc]initWithFrame:CGRectMake(0,0,100,50)];
titleLabel.textAlignment = NSTextAlignmentCenter;
titleLabel.text = #"PAKKELISTE";
[titleView addSubview:titleLabel];
self.navigationItem.titleView = titleView;
The details of the frames, text, alignment, etc. are just an example. The main idea though is that you set a custom UIView as the navigationItem's titleView.
It could also be an issue with your back button offset. Try this approach instead for removing the "back" text (I haven't tried this before, but I'm curious if it will work).
self.navigationController.navigationBar.topItem.title = #"";

iOS 7.1 update hide navigation bar left button by default

I have following code to create UINavigationBar and set the navigation item with a back button at the right side.
UINavigationBar *navBar = [[UINavigationBar alloc] initWithFrame:CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, 60)];
navBar.delegate = self;
UIBarButtonItem *back = [[UIBarButtonItem alloc] initWithTitle:#"Back" style:UIBarButtonItemStyleDone target:self action:#selector(backButtonTapped)];
UINavigationItem *backItem = [[UINavigationItem alloc] init];
[backItem setTitle:#"What's New"];
[backItem setLeftBarButtonItem:back];
backItem.leftBarButtonItem.enabled = YES;
[navBar pushNavigationItem:backItem animated:NO];
[self.view addSubview:navBar];
This worked perfectly until i update my xCode 5 to iOS 7.1 update recently.
But now when the UIView presented the navigation button is not visible. But when i touch the location of the button (where it used to be before the update), it shows me the button and click even is firing.
My question is how to set the button visible at the moment view is present to user ?
Thank you.
Try to initialize your UIBarButtonItem with initWithCustomView. Also, try to set buttonType of the UIButton to UIButtonTypeSystem.
Thanks to all,
finally what happen is as follows.
The above behaviour is not what i assume it is. When a new view is loaded the button is disappear by default and only if i move my finger here & there on the location button used to be it appears. Further when i keep the view still, after it loaded, about 15 seconds, button appears.
So i suspect this is with "viewDidLoad" method. (Code related to this UINavigationBar is in viewDidLoad method.
When I move above code to "viewDidAppear" method it start to work again.

UITextField with inputView showing UIPickerView... how to turn off translucency in IOS 7?

We have a tab bar. In one of the controllers, we have a UITextField. Clicking on that brings up a picker, using the inputView field of the UITextField. My team likes the look of that on iOS 6, but on iOS 7 they see the blurred background and tab bar coming through. Can I turn off that translucency, and where do I need to do that?
self.termsPickerView = [[UIPickerView alloc] initWithFrame:CGRectMake(0, 43, 320, 480)];
self.termsPickerView.delegate = self;
self.termsPickerView.dataSource = self;
[self.termsPickerView setShowsSelectionIndicator:YES];
self.termTextField.inputView = self.termsPickerView ;
self.termTextField.delegate = self;
UIPickerView in iOS 7.0 is translucent by default and that is the nature, and like all other views, is simple a background color controlling the color.
So to fix your problem you could do,
self.pickerView.backgroundColor = [UIColor whiteColor];
The apple documentation doesn't show any means of turning this transparency off.
tabBarController.tabBar.translucent = NO;

Customizing tint color of UIBarButtonSystemItem with UIAppearance API

I know I can customize the UIBarButtonItem text via
setTitleTextAttributes:forState:
There is also a way to customize UITabBar icons via
setSelectedImageTintColor:
Is there a way to customize the tint color of a UIBarButtonSystemItem, (e.g. the trash icon color), just to have a consistent UX? I could not find anything.
If this is not possible, how would I proceed? Should I save a color modified version of the icon? Where can I find it? What would be the easiest way to modify it?
EDIT
To clarify, it's not the background color of the UIBarButtonItem I am asking for, but the color of the contour of the icon.
EDIT
Setting the tint color of the UIBarButtonItem yields the background color of the button set.
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.window.backgroundColor = [UIColor whiteColor];
[self.window makeKeyAndVisible];
[[UINavigationBar appearance] setTintColor:[UIColor greenColor]];
UIBarButtonItem* trashButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemTrash target:nil action:nil];
trashButton.tintColor = [UIColor blackColor];
UIViewController* viewController = [[UIViewController alloc] init];
UINavigationController* navController = [[UINavigationController alloc] initWithRootViewController:viewController];
[viewController.navigationItem setRightBarButtonItem:trashButton];
self.window.rootViewController = navController;
return YES;
}
yields this.
EDIT 2
It turns out that the contour color of the system icons in fact can be set via tintColor property of UIBarButtonItem, however only if its style property has the value UIBarButtonItemStylePlain. (Even then, some colors are special and leave the contour white. One such color is [UIColor blackColor]) However, using the UIBarButtonItem in a UINavigationBar the style is forced to be UIBarButtonItemStyleBordered. In this case, tintColor sets the background color of the button and leaves the contour white.
As I am using the UIBarButtonItems in a navigation bar, my problem still remains unsolved.
Note: The following only works for buttons added to a toolbar, not a navbar.
Use the tintColor property of UIBarButtonItem. Either call it on a specific instance or call it on the appearance for all button items.
Be careful setting the tint for all button items via appearance. Not all button items look right when you set the tint.
Update:
UIBarButtonItem *btnAdd = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:#selector(addAction)];
btnAdd.tintColor = [UIColor blackColor];
This will make the button's icon black (the background will be whatever the toolbar's tint is).
I have solved my problem by changing the color of the bar button system item png file in an external editor, including that image to the project and loading it via
[[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:#"UIButtonBarTrashBlack"] style:UIBarButtonItemStyleBordered target:self action:#selector(myAction)];
I have found the internal system image using the helpful UIKit-Artwork-Extractor.
I have edited the color of the artwork using the free software GIMP.
Instead of using black color, use this:
[UIColor colorWithRed:0 green:0 blue:0 alpha:1]; // [UIColor
blackColor] makes it white

How to change UIWebview bottom toolbar color?

I have created a UIWebview in my app. I managed to change the background color of the navigation bar with setTintColor. However, I am unable to do the same for the bottom bar (with back/forward/refresh buttons). Can anyone help?
Did you create the bottom bar yourself? It probably is an UIToolbar:
UIToolbar *bottomToolbar = [[UIToolbar alloc] init];
bottomToolbar.tintColor = [UIColor redColor];

Resources