Set inactive tab tint color - xamarin.ios

How do you set the inactive tint color with Xamarin.iOS?
There are solutions for Xcode, but can't use them in Xamarin.

For The bottom text :
// This will change the text's color when the item is unselected
var attributes = new UITextAttributes();
attributes.TextColor = UIColor.Red;
TabBarItem.SetTitleTextAttributes(attributes, UIControlState.Normal);
var selectedAttributes = new UITextAttributes();
selectedAttributes.TextColor = UIColor.White;
TabBarItem.SetTitleTextAttributes(selectedAttributes, UIControlState.Selected);
For the icon:
// This will let the icon show the image's original color(instead of the gray) when the item is unselected
TabBarItem.Image = UIImage.FromBundle("imageName").ImageWithRenderingMode(UIImageRenderingMode.AlwaysOriginal);
You can also use the same method to set the image when the item is selected:
TabBarItem.SelectedImage = UIImage.FromBundle("imageName").ImageWithRenderingMode(UIImageRenderingMode.AlwaysOriginal);
Or just use TabBar.TintColor = UIColor.White;.

Related

How to change the color from Picker in Xamarin Mac?

I have a picker on my Xamarin mac app, I want to change the background color and the border color (blue), How can I do that?
Picker picker1 = new Picker { Items = { translateExt.transltR("Option1"), "Option2", "Option3" }, SelectedIndex = outputMode, WidthRequest = 210, TextColor = Color.FromHex(fileManagerPlatform.getColorText()), VerticalOptions = LayoutOptions.CenterAndExpand};
picker1.BackgroundColor = Color.Transparent;
The previous code works on Android, iOs, UWP to change the background color, but not on Mac.

navigation background image xamarin ios

I'm new in xamarin(start using 2 week), now I need do a background Image wtih navigation bar like below picture? how can I do it?
You need to add an UIImage in your UIViewController (filling whole or only top of ViewController) setting your UINavigationBar to a clear color with
YourNavigationBar.SetBackgroundImage(new UIImage(), UIBarMetrics.Default);
YourNavigationBar.ShadowImage = new UIImage();
YourNavigationBar.Translucent = true;
YourNavigationBar.BackgroundColor = UIColor.Clear;
To reset UINavigationBar transparency you have to use:
YourNavigationBar.SetBackgroundImage(null, UIBarMetrics.Default);

Is it possible to change inactive TabBarIOS Icon color in React Native?

As in subject, I am wondering if right now in React Native is an option to change color of inactive TabBar icon from default gray to custom color? With or without using react-native-vector-icons
I found solution, but your icon should be in "inactive" color. To achieve this go to RTCTabBarItem.m and change first line in method setIcon:
- (void)setIcon:(UIImage *)icon
{
_icon = [icon imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
if (_icon && _systemIcon != NSNotFound) {
_systemIcon = NSNotFound;
UITabBarItem *oldItem = _barItem;
_barItem = [UITabBarItem new];
_barItem.title = oldItem.title;
_barItem.imageInsets = oldItem.imageInsets;
_barItem.selectedImage = oldItem.selectedImage;
_barItem.badgeValue = oldItem.badgeValue;
}
self.barItem.image = _icon;
}
Then in all TabBarIOS.Item add field selectedIcon with the same url as in icon (that's no matter), set tintColor of TabBarIOS to "active" color and that's all! TabBar will be rendered with default icon color (inactive), and active icon will be in tintColor. I think that TabBar field renderAsOriginal should do this, but it not works. After all I found this solution on github https://github.com/facebook/react-native/issues/3083
Another solution (may not works in some cases):
in xCode find file RCTTabBar.m (cmd + shift + f)
find - (instancetype)initWithFrame:(CGRect)frame
add before return self:
[[UIView appearanceWhenContainedIn: [UITabBar class], nil] setTintColor: [UIColor redColor]];
[[UITabBar appearance] setSelectedImageTintColor: [UIColor greenColor]];
Restart Simulator/Device
In code redColor is color of inactive buttons, and greenColor is color of active button. For more details checkout this Unselected UITabBar color?
Edit: I found great tool if you want convert RGB to UIColor http://uicolor.xyz/

Changing the unselected color of a UITabBar Item iOS 9

override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.'
UITabBar.appearance().tintColor = UIColor.whiteColor()
UITabBar.appearance().selectedImageTintColor = UIColor.redColor()
} //method is in TabBarViewController
I would like the unselected color to be white and selected color to be red. The selectedImageTintColor property is deprecated in iOS 9, and I was wondering how I'd be able to change the unselected image color otherwise? Also, I was able to change the selected image tint color the red color in storyboard by changing the tabbar keypath's color attribute to red. I was wondering if there was a way of changing the unselected and selected color in storyboard?
Make sure your original image is displayed as white. Then you just tell the TabBarItem to render the unselected image as .AlwaysOriginal and the set a selectedImage on it like so:
let tabBarImage = UIImage(named: "icon-tab-name")
let tabBarItem = UITabBarItem(title: "Title", image: tabBarImage?.imageWithRenderingMode(.AlwaysOriginal), selectedImage: tabBarImage)
And then have
UITabBar.appearance().tintColor = UIColor.redColor()
This way you will have a white unselected state and a red selected state.
I did with this peace of code in the viewDidLoad method:
self.tabBar.tintColor = UIColor.whiteColor()
If you would like to change all of them in IOS 10, do something like this in the appDelegate. This is changing all the unselected ones to black.
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.
UITabBar.appearance().unselectedItemTintColor = UIColor(displayP3Red: 0, green: 0, blue: 0, alpha: 1)
return true
}

How to create an image-button

I create an image-button using below code:
ImageBrush btnBrush1 = new ImageBrush();
btnBrush1.Stretch = Stretch.Uniform;
btnBrush1.ImageSource = new BitmapImage(new Uri("ms-appx:/Images/icon_LogIn.png"));
btnLogIn.Background = btnBrush1;
The problem:
1) When using a mouse hovering the img-button, it turn grey background and icon disappear ( when not hovering the img-button, this image button is visible.
I want this image-button visible when hovering it or pressing it.
Thanks
You need to set Image as Content rather than setting ImageBrush as Background.
Try this
Image img=new Image();
img.Source=new BitmapImage(new Uri("/Images/icon_LogIn.jpg",UriKind.RelativeOrAbsolute));
btnLogIn.Content = img;

Resources