UINaviagationBar ignoring background color settings [duplicate] - ios

This question already has an answer here:
Unable to set barTintColor with custom RGBa in iOS7
(1 answer)
Closed 3 years ago.
ios 13, objective-c, can't get the navigation bar background color set.
I've tried setting the color via the UI in interface builder, and several examples off the web (and here).
UINavigationBarAppearance* navBarAppearance = [self.navigationController.navigationBar standardAppearance];
navBarAppearance.backgroundColor = [UIColor colorWithRed:172.0f green:193.0f blue:197.0f alpha:1.0f];
I would expect the above code to set the background color, but it's still white.

change this:
navBarAppearance.backgroundColor = [UIColor colorWithRed:172.0f green:193.0f blue:197.0f alpha:1.0f];
to this:
navBarAppearance.backgroundColor = [UIColor colorWithRed:172.0f/255.0f green:193.0f/255.0f blue:197.0f/255.0f alpha:1.0f];

Related

ios 11 color of the app (uinavigation)

Am using this color for the UINavigationController and some of other views
[UIColor colorWithRed:0.137 green:0.137 blue:0.145 alpha:1.00]
but there is a strange behaviour with iOS 11 when I run the application sometimes the color is correct (dark) and sometimes the color be in light mode a lighter than the original color
Replace
[UIColor colorWithRed:0.137 green:0.137 blue:0.145 alpha:1.00]
with
[UIColor colorWithRed:137.0/255.0 green:137.0/255.0 blue:145.0/255.0 alpha:1.00]

Can I change the background color of the Chromecast navigation bar?

I've reviewed the custom styles available in the GoogleCast v3 SDK and unless I'm missing something I don't see a way to change the backgroundColor of the deviceChooser. See below:
Is there any way to change this gray color?
As per the documentation Google does not allow us to change the navigation bar style. So we might need to change the navigation bar appearance before pushing to the media control UI of SDK.
I tried it in didFinishLaunchingWithOptions
[UINavigationBar appearance].barTintColor = [UIColor whiteColor];
[UINavigationBar appearance].translucent = NO;
Hope it helps :)
There are different ways you can customize the style on Chromecast SDK for iOS by using:
GCKUIStyle.sharedInstance()
My contribution for style the navigation bar:
From DOCUMENTATION I can see the following diagram
The common thing between all the "Style class" is that all of them inherit from GCKUIStyleAttributes so:
func configureChromecast() {
let gckCriteria = GCKDiscoveryCriteria(applicationID: "ABC123")
let gckCastOptions = GCKCastOptions(discoveryCriteria: gckCriteria)
GCKCastContext.setSharedInstanceWith(gckCastOptions)
GCKLogger.sharedInstance().delegate = self
// General
let textColor: UIColor = UIColor.black
let backgroundColor: UIColor = UIColor.white
GCKUIStyle.sharedInstance().castViews.backgroundColor = backgroundColor
GCKUIStyle.sharedInstance().castViews.headingTextColor = textColor
GCKUIStyle.sharedInstance().castViews.headingTextFont = UIFont.textStyleRegular
GCKUIStyle.sharedInstance().castViews.bodyTextColor = textColor
GCKUIStyle.sharedInstance().castViews.bodyTextFont = UIFont.textStyleRegular
GCKUIStyle.sharedInstance().castViews.captionTextColor = textColor
GCKUIStyle.sharedInstance().castViews.captionTextFont = UIFont.textStyleRegular
GCKUIStyle.sharedInstance().castViews.buttonTextColor = textColor
GCKUIStyle.sharedInstance().castViews.buttonTextFont = UIFont.textStyleRegular
GCKUIStyle.sharedInstance().castViews.iconTintColor = textColor
// Navigation & Toolbar
let navigationBackgroundColor: UIColor = UIColor.blue
let navigationtintColor: UIColor = UIColor.white
GCKUIStyle.sharedInstance().castViews.deviceControl.connectionController.navigation.backgroundColor = navigationBackgroundColor
GCKUIStyle.sharedInstance().castViews.deviceControl.connectionController.toolbar.backgroundColor = navigationBackgroundColor
GCKUIStyle.sharedInstance().castViews.deviceControl.connectionController.navigation.headingTextColor = navigationtintColor
GCKUIStyle.sharedInstance().castViews.deviceControl.connectionController.toolbar.headingTextColor = navigationtintColor
GCKUIStyle.sharedInstance().castViews.deviceControl.connectionController.navigation.bodyTextColor = navigationtintColor
GCKUIStyle.sharedInstance().castViews.deviceControl.connectionController.toolbar.bodyTextColor = navigationtintColor
GCKUIStyle.sharedInstance().castViews.deviceControl.connectionController.navigation.captionTextColor = navigationtintColor
GCKUIStyle.sharedInstance().castViews.deviceControl.connectionController.toolbar.captionTextColor = navigationtintColor
GCKUIStyle.sharedInstance().castViews.deviceControl.connectionController.navigation.buttonTextColor = navigationtintColor
GCKUIStyle.sharedInstance().castViews.deviceControl.connectionController.toolbar.buttonTextColor = navigationtintColor
GCKUIStyle.sharedInstance().castViews.deviceControl.connectionController.navigation.iconTintColor = navigationtintColor
GCKUIStyle.sharedInstance().castViews.deviceControl.connectionController.toolbar.iconTintColor = navigationtintColor
GCKUIStyle.sharedInstance().apply()
}
And the result:
The Navigation Bar style in question doesn't come from GoogleCast SDK (at least for version 4.6.1 dynamic on iOS 15) but from your own app's appearance. A way to change the background and title text color of the Navigation Bar (on GoogleCast SDK View Controllers, but your own app's as well) is to add
UINavigationBar.appearance().backgroundColor = UIColor.darkGray
UINavigationBar.appearance().titleTextAttributes = [NSAttributedString.Key.foregroundColor:UIColor.white]
in your AppDelegate's didFinishLaunchingWithOptions function.
But, no matter what tint color field I try setting for either UINavigationBar or UIBarButtonItem appearance, I can't get the Cancel button text color to change. I noticed that behavior in my app as well, only the Navigation Bar Buttons that have the tint set as Default in the Storyboard are affected by this global change, specifically by setting
UIBarButtonItem.appearance().tintColor = UIColor.yellow
If on the other hand you set a color in the Storyboard yourself, it will not be changed by the line of code above. This conclusion leads me to believe that is the way the Device Chooser View Controller was created, with a tint color set explicitly.
But, I see in one of the comments to the main question that someone was able to change the Cancel button color (as seen in the screenshot as well), so if anyone can share that piece of code it would be extremely appreciated.
Thanks!
EDIT
And of course only after posting this I tried pasting the entire code snippet from Reimond Hill and it worked in changing the Cancel button color, specifically this
GCKUIStyle.sharedInstance().castViews.deviceControl.connectionController.navigation.buttonTextColor = navigationtintColor
The reason why I thought this wouldn't work first time around is the fact that we are setting the navigation property of the Connection Controller, not the Device Controller (which doesn't even have this property). So I hope this will help someone else not waste time on this like I did.
You can style all GCK views using GCKUIStyle,
for example:
GCKUIStyle.sharedInstance().castViews.mediaControl.miniController.buttonTextColor = .black
GCKUIStyle.sharedInstance().apply()
in your case, the navigation can be styled with this line
connectionController.navigation.backgroundColor = UIColor.black
Check this URL for more info:
https://developers.google.com/cast/docs/ios_sender/customize_ui

How to set UIBarButtonItem tintcolor to non default UIColor

I've looked through all the typical navigation bar tintcolor tutorials and questions. I have a set tint for the navigation bar, but I have a mail icon that needs to change to a custom color when there is mail. (like reddit orange mail icon)
I can set the tint properly only when using system UIColors.
self.leftNavigationBarButton = [[UIBarButtonItem alloc] initWithImage:someImage style:UIBarButtonItemStylePlain target:self action:#selector(foo:)];
self.navigationItem.leftBarButtonItem = self.leftNavigationBarButton;
self.leftNavigationBarButton.tintcolor = [UIColor redColor];
However if I then use a custom color.
self.leftNavigationBarButton.tintcolor = [UIColor colorWithRed:100 green:40 blue:20 alpha:1.0];
It makes the icon white. Does anyone know what's going on or how I can use a custom color?
I figured it out from this answer https://stackoverflow.com/a/5642229/1732711.
Short answer is to divide the RGB values by 255.0.
self.leftNavigationBarButton.tintcolor = [UIColor colorWithRed:100/255.0 green:40/255.0 blue:20/255.0 alpha:1.0];

How can I get the iOS 7 default blue color programmatically?

I'm creating custom elements in my app and want to match the look and feel of the new iOS. iOS 7 introduced to us a very common lighter blue color, the default color or tint for several elements, including the system button, segmented control, etc. They've made it easy to select the color using IB, as seen here:
However, I haven't found how to easily access the color programmatically. I checked out the UIColor documentation, and there doesn't seem to be any accessor for the blue system color in the class itself.
Here's my question: does a simple accessor exist for this color? [UIColor ?] or something like it? If not, does someone know the exact RGB values for that color?
Use self.view.tintColor from a view controller, or self.tintColor from a UIView subclass.
It appears to be [UIColor colorWithRed:0.0 green:122.0/255.0 blue:1.0 alpha:1.0].
iOS 7 default blue color is R:0.0 G:122.0 B:255.0
UIColor *ios7BlueColor = [UIColor colorWithRed:0.0 green:122.0/255.0 blue:1.0 alpha:1.0];
According to the documentation for UIButton:
In iOS v7.0, all subclasses of UIView derive their behavior for tintColor from the base class. See the discussion of tintColor at the UIView level for more information.
Assuming you don't change the tintColor before grabbing the default value, you can use:
self.view.tintColor
Here is a simple method to get the default system tint color:
+ (UIColor*)defaultSystemTintColor
{
static UIColor* systemTintColor = nil;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
UIView* view = [[UIView alloc] init];
systemTintColor = view.tintColor;
});
return systemTintColor;
}
Hex Color code
#007AFF
and you need this libary
https://github.com/thii/SwiftHEXColors
ps. iOS, Swift
swift 4 way:
extension UIColor {
static let system = UIView().tintColor!
}
Native extension with predefined system colors gives what you're looking for:
// System colors
extension UIColor {
/* Some colors that are used by system elements and applications.
* These return named colors whose values may vary between different contexts and releases.
* Do not make assumptions about the color spaces or actual colors used.
*/
...
#available(iOS 7.0, *)
open class var systemBlue: UIColor { get }
...
}
You can use it directly:
myView.tintColor = .systemBlue
Get the color automatically by using this code:
static let DefaultButtonColor = UIButton(type: UIButtonType.System).titleColorForState(.Normal)!
The UIWindow.tintColor method wasn't working for me in iOS8 (it was still black), so I had to do this:
let b = UIButton.buttonWithType(UIButtonType.System) as UIButton
var color = b.titleColorForState(.Normal)
This gave the proper blue tint seen in a UIBarButtonItem
From iOS 7 there is an API and you can get (and set) the tint color with:
self.view.tintColor
Or if you need the CGColor:
self.view.tintColor.CGColor
In many cases what you need is just
[self tintColor]
// or if in a ViewController
[self.view tintColor]
or for swift
self.tintColor
// or if in a ViewController
self.view.tintColor
Please don't mess with view.tintColor or extensions, but simply use this:
UIColor.systemBlue
while setting the color you can set color like this
[UIColor colorWithRed:19/255.0 green:144/255.0 blue:255/255.0 alpha:1.0]
Adding a category to UIColor the following way will make it available to you anytime you need it or even change its definition accross your code:
#interface UIColor (iOS7Colors)
+ (instancetype)iOS7blueColor;
#end
#implementation UIColor (SpecialColors)
+ (instancetype)iOS7blueColor;
{
return [UIColor colorWithRed:0.0f green:0.22f blue:122.0/255.0 alpha:1.0f];
}
Once you import the Category in your code you can call the color by using:
UIColor *myBlueColor = [UIColor iOSblueColor];

Change pressed color of UIButton [duplicate]

This question already has answers here:
Is it possible to change a UIButtons background color?
(17 answers)
UIButton selection color [duplicate]
(5 answers)
Closed 9 years ago.
Is there any way to change the color of a UIButton when it's pressed?
The default seems to be a blue color, but I don't see where or how to change this to a custom color.
Thanks!
If you are using storyboard then in inspector window you can change the highlight tint property to the color you want on button click event.
Look at the Highlight Tint property in image.
I ultimately followed the following poster's suggestion. It worked perfectly.
https://stackoverflow.com/a/10670141/720175
In my particular case I created a subclass of UIButton, with the final code as:
-(void) setHighlighted:(BOOL)highlighted
{
if(highlighted) {
self.backgroundColor = [UIColor colorWithRed:1 green:0.643 blue:0.282 alpha:1];
} else {
self.backgroundColor = [UIColor colorWithRed:1 green:1 blue:1 alpha:1];
}
[super setHighlighted:highlighted];
}
Easy as pie.

Resources