iOS Tint Color

JohnCHarrisJohnCHarris ✭✭USMember ✭✭
edited February 2015 in Xamarin.Forms

Is it possible to set the tint color for the iOS version of an application?

With the following code I have a namespace named Static with a default Xamarin.Forms color defined. I'm trying to run this in my App delegate.

global::Xamarin.Forms.Forms.Init();
LoadApplication(new App());

// Set the tint color
if (UIDevice.CurrentDevice.CheckSystemVersion(7, 0))
{
    var tintColor = Static.ColorResources.TintColor;
    UIApplication.SharedApplication.KeyWindow.TintColor = UIColor.FromRGB((nfloat)tintColor.R, (nfloat)tintColor.G, (nfloat)tintColor.B);
}

When I run this UIApplication.SharedApplication.KeyWindow is null.

Posts

  • adamkempadamkemp mod USInsider, Developer Group Leader mod

    Call base.FinishedLaunching after calling LoadApplication. That is what triggers the call to window.MakeKeyAndVisible(), which is what sets the application's KeyWindow property.

  • JohnCHarrisJohnCHarris ✭✭ USMember ✭✭

    I changed my FinishedLaunching method and no luck.

    global::Xamarin.Forms.Forms.Init();
    LoadApplication(new App());
    
    bool result = base.FinishedLaunching(app, options);
    
    // Set the tint color
    if (UIDevice.CurrentDevice.CheckSystemVersion(7, 0))
    {
        var tintColor = Static.ColorResources.TintColor;
        UIApplication.SharedApplication.KeyWindow.TintColor = UIColor.FromRGB(new nfloat(tintColor.R), new nfloat(tintColor.G), new nfloat(tintColor.B));
    }
    
    return result;
    

    Does Xamarin Forms override this color?

  • adamkempadamkemp mod USInsider, Developer Group Leader mod

    It doesn't look like they do. Try using a stock Xamarin.iOS project and make sure what you're trying to do works from there. Use the exact numbers (by inspecting with the debugger). You may not be using the right kind of number. iOS uses fractional values (0-1), but maybe the Forms color uses 0-255. I think there's an extension method to convert from the Xamarin.Forms color type to UIColor.

  • GercoBrandwijkGercoBrandwijk ✭✭ USMember ✭✭
    edited April 2015

    @JohnCHarris Did you figured out a solution for this? I also want to set the tint color..

    EDIT: It looks like your color was wrong, because this works in my case:
    Boolean result = base.FinishedLaunching(app, options); UIApplication.SharedApplication.KeyWindow.TintColor = DependencyService.Get<IDSA_Style>().GetColorPrimaryDark().ToUIColor(); return result;

  • JohnCHarrisJohnCHarris ✭✭ USMember ✭✭

    @GercoBrandwijk I never got it working. I ended up using a style in xaml instead. I'm glad to see you got it going.

  • SurbhiAroraSurbhiArora ✭✭ USMember ✭✭

    @GercoBrandwijk Can you please share what you did for IDSA_Style ?

Sign In or Register to comment.