I want to modify the background color transparency of NavigationBar, but the above code doesn't work.
NavigationBar(
modifier = Modifier.background(Color.Transparent),
tonalElevation = 0.dp,
containerColor = colorScheme.secondaryContainer.copy(0.7f),
contentColor = colorScheme.primary) {
}
Related
Since iOS13‘s darkmode i‘m working on supporting it in my Xamarin.Forms application. Everything works fine beside the StatusBar color when a NavigationBar is displayed. The usual behaviour of the Bar should be to change backgroundColor accordingly to the BGColor of the Navbar, but for some reason it always stays white.
I‘ve tried coloring it manually like this
UIView statusBar = UIApplication.SharedApplication.ValueForKey(new NSString("statusBar")) as UIView;
statusBar.BackgroundColor = UIColor.FromRGB(61, 205, 88);
But it didn‘f change anything.
Below a screenshot of how it looks
In Xamarin.Forms Application , modifying Status Bar need to edit Info.plist in iOS solution .
First, Add UIViewControllerBasedStatusBarAppearance to file :
<key>UIViewControllerBasedStatusBarAppearance</key>
<false/>
//Follow can change text color of status bar
//<key>UIStatusBarStyle</key>
//<string>UIStatusBarStyleDarkContent</string>
Second, in Xamarin.iOS project , you can modify statsbar background in AppDelegate.cs as follow :
public override void OnActivated(UIApplication uiApplication)
{
if (UIDevice.CurrentDevice.CheckSystemVersion(13, 0))
{
// If VS has updated to the latest version , you can use StatusBarManager , else use the first line code
// UIView statusBar = new UIView(UIApplication.SharedApplication.StatusBarFrame);
UIView statusBar = new UIView(UIApplication.SharedApplication.KeyWindow.WindowScene.StatusBarManager.StatusBarFrame);
statusBar.BackgroundColor = UIColor.Red;
statusBar.TintColor = UIColor.White;
UIApplication.SharedApplication.KeyWindow.AddSubview(statusBar);
}
else
{
UIView statusBar = UIApplication.SharedApplication.ValueForKey(new NSString("statusBar")) as UIView;
if (statusBar.RespondsToSelector(new ObjCRuntime.Selector("setBackgroundColor:")))
{
statusBar.BackgroundColor = UIColor.Red;
statusBar.TintColor = UIColor.White;
UIApplication.SharedApplication.StatusBarStyle = UIStatusBarStyle.BlackOpaque;
}
}
base.OnActivated(uiApplication);
}
You can also have a look at this discussion .
I am coding my app using Xamarin, but I can translate any swift/objective-C responses.
I have a WKWebView that I using to display data with LoadHtmlString(). I want to change the background color of the UIToolbar that is displayed above the keyboard when a user focuses an input field. Right now, the button text color and background color are both white, so the buttons aren't visible.
I can change the button text color by using UIBarButtonItem.Appearance.TintColor = UIColor.White;, but this will also change the text color of the buttons in my UINavigationBar. I would rather leave the text white, and change the background color of the UIToolbar.
I can slightly modify the background color using UIToolbar.Appearance.BackgroundColor = UIColor.Red;, but this just adds a subtle tint of the color to the UIToolbar, and doesn't actually make the toolbar dark enough for the white text to be visible.
Here is my complete code for setting up my Appearance defaults:
UIColor lightColor = UIColor.White;
UIColor themeColor = UIColor.Red;
UIApplication.SharedApplication.SetStatusBarStyle(UIStatusBarStyle.LightContent, false);
UINavigationBar.Appearance.BarStyle = UIBarStyle.Black;
UINavigationBar.Appearance.BarTintColor = themeColor;
UINavigationBar.Appearance.Translucent = false;
UINavigationBar.Appearance.TintColor = lightColor;
UINavigationBar.Appearance.SetTitleTextAttributes(new UITextAttributes()
{
TextColor = lightColor
});
UIStringAttributes navBarAttributes = new UIStringAttributes();
navBarAttributes.ForegroundColor = lightColor;
UINavigationBar.Appearance.TitleTextAttributes = navBarAttributes;
UITabBar.Appearance.BarTintColor = themeColor;
UITabBar.Appearance.TintColor = lightColor;
UIToolbar.Appearance.BarTintColor = themeColor;
UIToolbar.Appearance.TintColor = lightColor;
UIBarButtonItem.Appearance.TintColor = lightColor;
UIButton.AppearanceWhenContainedIn(typeof(UINavigationBar)).TintColor = lightColor;
UIToolbar.Appearance.BackgroundColor = themeColor;
Is there a way to change the WKWebView's toolbar background color without having to retheme my entire app?
If I can't change the background color of the toolbar, I am open to changing the button text color when displayed in a WKWebView. I have tried adding the following code, but nothing seems to work.
//Using green to see if the code is working.
UIBarButtonItem.AppearanceWhenContainedIn(typeof(WKWebView)).TintColor = UIColor.Green;
UIBarButtonItem.AppearanceWhenContainedIn(typeof(MyViewController)).TintColor = UIColor.Green;
You can have a try with custom UIToolBar to change its background color by an image :
public class MyToolBar: UIToolbar
{
public override void Draw(CGRect rect)
{
base.Draw(rect);
CGContext c = UIGraphics.GetCurrentContext();
UIImage image = new UIImage("background.png");
//here set image to be background color
c.DrawImage(rect, image.CGImage);
}
}
And toolbar will only used for where you used , can not affecting other toolbar in app.
MyToolBar myToolBar = new MyToolBar();
myToolBar.Frame = new CoreGraphics.CGRect(0, 0, UIScreen.MainScreen.Bounds.Size.Width, 50);
UIBarButtonItem doneItem = new UIBarButtonItem("Done", UIBarButtonItemStyle.Done, doneClickMethod);
List<UIBarButtonItem> list = new List<UIBarButtonItem>();
list.Add(doneItem);
myToolBar.Items = list.ToArray();
MySearchBar.InputAccessoryView = myToolBar;
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
I want to know how to set Transparent background Color in iOS. I have searched everywhere but I can't find anything. I want to set transparent background color like this:
Set opaque to NO and alpha to 0.3, like this:
UIImageView *myImageView = ...
myImageView.opaque = NO;
myImageView.alpha = 0.3;
try this one it will works :-
Your_ImageView.opaque = NO;
Your_ImageView.alpha = 0.3;
I would like to animate barTintColor property when transitioning from one view controller to another.
I have tried with following solution:
[[self transitionCoordinator] animateAlongsideTransition:^(id<UIViewControllerTransitionCoordinatorContext> context) {
self.navigationController.navigationBar.translucent = NO;
self.navigationController.navigationBar.barTintColor = [UIColor redColor];
} completion:nil];
which animates barTintColor as it should but my navigation bar should be translucent. To fix this problem I tried to set it to translucent = YES in completion block of trasitionCoordinatoranimation. Like this:
completion:^(id<UIViewControllerTransitionCoordinatorContext> context) {
self.navigationController.navigationBar.translucent = YES;
}
but that causes slight jump in barTintColor value of navigation bar after the animation is completed. This is expected since translucent and opaque colors are different.
Similar questions:
[1]
[2]
Thanks in advance!
EDIT:
I forgot to add that some strange scale animation appears from top left corner in navigation bar if I remove the self.navigationController.navigationBar.translucent = NO; line from animation block. So that's not the solution either.
I'm going to answer my own question while still being open for other suggestions/solutions.
My solution which I think is quite a "clean one" is to make an alpha blended color from original color with appropriate blend color. So let's say we have a white background behind a navigation bar and we would like to animate current navigation bar barTintColor to green color. In this case we have to blend original green color with white color and appropriate alpha value.
After some playing with values I found out that alpha 0.16 works best for iOS 7 cases (I haven't tested it on other OS versions).
Animation block written in my original question implemented with my solution looks like this:
Pay attention to ALPHA BLENDED ORIGINAL COLOR and ORIGINAL COLOR
[[self transitionCoordinator] animateAlongsideTransition:^(id<UIViewControllerTransitionCoordinatorContext> context) {
self.navigationController.navigationBar.translucent = NO;
self.navigationController.navigationBar.barTintColor = <ALPHA BLENDED ORIGINAL COLOR>;
} completion:^(id<UIViewControllerTransitionCoordinatorContext> context) {
self.navigationController.navigationBar.barTintColor = <ORIGINAL COLOR>;
self.navigationController.navigationBar.translucent = YES;
}];
Equation for alpha blending:
CGFloat bR = ((bcR - cR) * alpha + cR);
CGFloat bG = ((bcG - cG) * alpha + cG);
CGFloat bB = ((bcB - cB) * alpha + cB);
values being:
cR, cG, cB = original color R,G,B components
bcR, bcG, bcB = blending color R,G,B components
alpha = alpha value to blend with
================================================
bR, bG, bB = blended R,G,B components
Anyone who likes this solution is welcome to use a UIColor's category for alpha blending I wrote for this case. You can find it here.
Thanks.