UITextField backgroundColor in UISearchBar iOS 10+ - uitextfield

I'm trying to set the background color of the text field in my search bar to a custom color. I looked at the answer here to no avail:
Cannot change search bar background color
See how that search bar has a red text field? I followed the code and can even verify that the UISearchBarTextField object was found and the background color of it is being set to UIColor.red, but the color does not change.
I've messed around with all the background colors of the superviews with hopes that it might help but I cannot get that color to change. Maybe there's some new trick or someone can shed some light on something that may be overriding the color somehow.
extension UISearchBar {
var textField: UITextField? {
return subviews.first?.subviews.first(where: { $0.isKind(of: UITextField.self) }) as? UITextField
}
}
searchBar.textField?.backgroundColor = UIColor.red // <-- Not working
let textFieldInsideUISearchBarLabel = searchBar.textField?.value(forKey: "placeholderLabel") as? UILabel
textFieldInsideUISearchBarLabel?.textColor = UIColor.lightGray
Note that the text inside the UITextField object is changing to the lightGray like I want it, just not the UITextField background color.

After a long wait for an answer, I decided to try some experiments. I created a new project, dragged a search bar, connected it to the ViewController, added the UISearchBar extension, and set the color - exactly the same as I did in my main project.
Voila! It does set the background color as it should, and as it shows in the linked topic in the main question.
So, I put the projects side by side, opened the storyboard in each of them and started setting the properties of the searchBar, one at a time, until I could see why the bar is not being set like it should in the main project.
The very first thing I tried was, search style. My project has it set to "Minimal". I changed it to "Minimal" in the test project and noticed right away that the color was no longer set.
So, setting the "Search Style" property of the searchBar in the main project to "Default" allowed that background color to be set.
I would appreciate it greatly if anyone could comment and say why it is that I can't use "Minimal" if I want to customize the background color, or how I could make it work.

Related

Change Side-Menu Button/Link Text Colour Dynamically Xamarin.iOS

I'm using a Side Menu iOS (not my choice just by the way) and I stumbled upon an issue that can be seen in the following image:
If you look close enough in the above figure, the red rectangle is actually highlighting the text 'Menu' that used to open the side menu and it's barely visible. It's quite simply changing the navigation bar text color which doesn't seem to affect that color.
How do I change the default color that is appearing above?
The tint determines this color.
You can change it globally by settting
UINavigationBar.Appearance.TintColor
If you just want to change the color of the menu button in a specific ViewController . Add the following code in the method ViewWillAppear() of your ViewController
public override void ViewWillAppear(bool animated)
{
base.ViewWillAppear(animated);
this.NavigationController.NavigationBar.TintColor = UIColor.FromRGB(xxx,xxx,xxx);
}
NavigationPage has a property called BarTextColor, on iOS devices, this property changes the colour of both the navigation bar text and the menu button text. The following solution might be a problem though if one would like to have separate colours for each of the latter:
MainPage = new NavigationPage(YourPage) { BarBackgroundColor = Color.FromHex(#SomeHex), BarTextColor = Color.Red};
BarTextColor = Color.Red produces the following output:

UIDatePicker Background isn't changing

I've been trying to change the background && text color for the UIDatePicker, I'm executing this code via ViewDidLoad. The text color changes, but the background color refuses to change. Instead when I run the app and the view loads for the first time, it doesn't change the color, but if I tap inside of the textfield then go to the previous screen then click on the textfield the background color changes like it's supposed to. This is my code for the viewdidload method below:
UIDatePicker *endTimeDatePicker = [[UIDatePicker alloc]init];
endTimeDatePicker.backgroundColor = [UIColor colorWithRed:0/255
green:0/255 blue:0/255 alpha:0.8];
[endTimeDatePicker setValue:[UIColor whiteColor] forKey:#"textColor"];
[endTimeDatePicker setDate:startTime];
endTimeDatePicker.datePickerMode = UIDatePickerModeDate;
[endTimeDatePicker addTarget:self action:#selector(updateEndTime:)
forControlEvents:UIControlEventValueChanged];
[promoEndTime setInputView:endTimeDatePicker];
I'm really at a loss, I also tried other variations to set the background color...
setbackground color, set tintcolor, uicolor black
still nothing, still the same result, any assistance would be great thanks.
Normally setting backgroundColor is all that's needed. If you had added the date picker in interface builder, it would work. I suspect that when you call setInputView, your promoEndTime is overriding that setting by changing it to something else.
You might get around that by setting the background color after calling setInputView. But you might find it better to change your strategy, because date pickers are notoriously resistant to UI changes. You're already on thin ice here with Apple, because the textColor setting is undocumented. Using undocumented API is a major risk of having Apple reject your app from the store. I agree that better appearance customization would be extremely nice here, but changing the text color is asking for trouble from Apple.
In case anyone is looking for a way to change background color of calendar popup on new ios 14 uidatepicker compact style then this is what worked for me:
(UIVisualEffectView.classForCoder() as? UIAppearanceContainer.Type).map({ UIDatePicker.appearance(whenContainedInInstancesOf: [$0]).backgroundColor = UIColor.yellow })

Is there predefined NSColor for the Dock and Menubar on OS X?

There are some NSColor initialization helpers like controlColor() which return various colors of system components. Is there any such thing for the dock and menubar? I couldn't see one by name that popped out. If there is no such helper, is there another way to get the color?
I want to use it as the default NSWindow background color for a utility application I am developing that will be displayed in a small, borderless NSWindow.
They are both controlled from the 'General' panel in 'System Preferences' shown in the figure below.
Thanks in Advance.
No, the menu bar and Dock background appearances aren't NSColor system colors. They do look a lot like the Dark Vibrant and Light Vibrant styles you can get from NSVisualEffectView, though.
If you want to change your view's appearance to match the state of the "Use dark menu bar and Dock" preference... well, there's no API for that, but you can read that preference from where it's stored. (Since it's not API, caveat emptor: there's no guarantee the preference storage won't change in later OS X versions.)
In Swift (and broken into several lines for clarity):
let defaults = NSUserDefaults.standardUserDefaults()
let globalPrefs = defaults.persistentDomainForName(NSGlobalDomain)!
let interfaceStyle = globalPrefs["AppleInterfaceStyle"]
if interfaceStyle as! String == "Dark" {
// time to be all emo
}

Status bar changing tint color when navigation bar going to hidden XCode

I'm using RKSwipeBetweenViewControllers
to switch between UIViewControllers by swipe, and it's all good, but here is a some strange thing i stuck with(look at the screen):
I made that if you scroll news feed down - navigation title going to hidden, and here is curious thing happening: when navigation title disappear - Status bar changing tint color to black! I just don't understand how it's possible?
I already added to to appDelegate
[UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleDefault;
and
-(UIStatusBarStyle)preferredStatusBarStyle{
return UIStatusBarStyleLightContent;
}
to every possible controllers, and of course navigation bar style i set to "black" but alas! Can anyone say me how to fix it? I will be really appreciate about it!
I had the same problem. What I did was add
override func preferredStatusBarStyle() -> UIStatusBarStyle {
return UIStatusBarStyle.LightContent
}
inside the UIViewController.
This is in swift though. I guess you need to override the function.

Interface Builder change text color bug?

This is driving me bananas..
If I select a UITextField in interface builder and go to change the text colour by manually entering the R G B values it changes the colour of the entire frame and background.
However if I change it using the sliders it changes the text colour only like I want.
Leads me to think its a bug... does this happen for anyone else?
I see this happening with the latest version of Xcode as well. Both the Text Color and Background Color controls in the UILabel attribute inspector change at the same time when manually typing in a R G B value, whereas if I choose a color another way (e.g. from the crayons or palette views in the Color picker), only the text color control value changes.
I'd assume this is a bug (and should be filed via http://bugreporter.apple.com), but then again it's persisted through a few versions of Xcode so this may be their expected behavior on purpose. But I'd definitely agree you should file it as a bug.
Definitely a bug! A temporary solution is to double click the text on the UILabel i.e. selecting all the UILabel text in the UI (storyboard or xib). Only so using the sliders changes the text colour. Hope it helps
Or change the color and then set the background color back to transparent. For me the fastest workaround. Same bug with UILabel.
You can try selecting the text you want to change the color of, then click T to open the fonts window and change the color from there. Working for me on Xcode 11.2.1.

Resources