Forum Xamarin Xamarin.Forms

Xamarin Color - Same Value different Tone in iOS

RaphaelChiorlinRanieriRaphaelChiorlinRanieri BRMember ✭✭✭
edited September 2016 in Xamarin.Forms


When using same RGB value in specific ios code and shared code I'm getting different tones of colors.

When I set my bar color to:

        UINavigationBar.Appearance.BarTintColor = UIColor.FromRGB(250, 92, 67);

I get exactly this color in a print screen.

But when using this exactly same value in shared code to a frame background.

    Frame frame = new Frame
            OutlineColor = Color.Transparent,
            BackgroundColor = Color.FromRgb(250, 92, 67),
            HasShadow = false,
            HorizontalOptions = LayoutOptions.Start,
            VerticalOptions = LayoutOptions.Start,

I get a visible different tone. And when seeing it in a print screen it turns in 253, 115, 84 .

Someone could give a help?
I found a similar problem here but do not know what to do.

In attach a pic where we can see the difference.

The up one is the right 250, 92, 67.
The bottom one is the 253, 115, 84 from shared code .


  • Any Hint?

  • Please,

    Some one can help?

    I do not have any clue to star looking

  • RotkivRotkiv USMember

    Did u try to use hex or Rgba to see is there some difference ?

  • @Rotkiv Yes, I used rgb, rgba, hex and the difference still happening.

  • BenBishopBenBishop USBeta ✭✭

    Hi Raphael,
    By default the Navigation Bar in iOS is translucent (ie transparent.)

    Can you do the following and see if it makes the colors match:
    UINavigationBar.Appearance.Translucent = false;

  • @BenBishop The translucent property is already set to false.
    In the Nav Bar, the color is right! If I use Rgb(250, 92, 67) the color I get in the emulator is this one.

    The problem is in the Xamarin Color.FromRgb / FromHex function, in shared code, that returns a wrong color... for some reason.

  • RotkivRotkiv USMember

    So you need to make custom render and use UIColor and I think will fix this.
    ex. public UIColor SelectedDateForegroundColor = Color.FromHex("#ffffffff").ToUIColor();

  • RaphaelChiorlinRanieriRaphaelChiorlinRanieri BRMember ✭✭✭
    edited September 2016

    @Rotkiv I would have to do a custom renderer for each element if this is the case, right?

    For example to set the correct color in a Frame, I would have to create a Frame CustomRenderer in iOS that would convert the color to UIColor...

    And another for a Label, and another for etc...

    I think this is a wrong path to take... Xamarin should already do it... I was thinking that could be about some configuration thing...

    I dont know how xamarin set the colors but in the core of the application this conversion to UIColor must already be done.

  • I just did a sample!
    If anyone from Xamarin Team could give a help too...
    Seems like to me that it is caused for some thing that the mono or xamarin does to convert the color.

  • @TheRealJasonSmith Could you confirm if this is a bug or not please? :)
    Tks :D

  • No one can help? Will file a bug for this...

  • A bug was opened last week:

    However I still have no answer.

    If anyone knows a solution let me know.

  • AdrianKnightAdrianKnight USMember ✭✭✭✭

    @RaphaelChiorlinRanieri I updated the bug thread. To fix the color issue, update to the latest pre-release.

    @SamanthaHouts Frame corner radius stopped working (shows flat) after 301. Was this intended?

  • SamanthaHoutsSamanthaHouts USXamarin Team Xamurai

    @AdrianKnight It was not! Which platform?

  • AdrianKnightAdrianKnight USMember ✭✭✭✭

    @SamanthaHouts only tested iOS.

  • SamanthaHoutsSamanthaHouts USXamarin Team Xamurai

    This should be fixed in 2.3.3-SR1. Thanks!

  • DaddoonDaddoon FRMember ✭✭

    Is Xamarin.Forms the 2.3.3-SR1 ? Because i have the same problem and the error still occur on this version.
    Thanks in advance!

  • DaddoonDaddoon FRMember ✭✭

    Ignore my previous post, i assume you were talking about this for upcoming Xamarin.iOS Service Release.

  • Chris.CastrianniChris.Castrianni USUniversity ✭✭

    This behaves like a CGColorSpace mismatch problem.

    With iOS 10, Apple began using sRGB rather than GenericRGB (see Color and Color Spaces section of UIColor docs).

    Looking at the repro app attached to Bug 44600, the nav bar is rendered in sRGB with value (250, 92, 67) and the Frame background is rendered in Generic RGB with value (250, 92, 67) resulting in different colors on the screen.

    The issue might be ColorExtensions.ToCGColor().

    Shouldn't the implementation be something like this?

    public static CGColor ToCGColor(this Color color)
        return new CGColor(CGColorSpace.CreateSrgb(), 
            new nfloat[] { (float)color.R, (float)color.G, (float)color.B, (float)color.A});
  • RaphaelChiorlinRanieriRaphaelChiorlinRanieri BRMember ✭✭✭

    @SamanthaHouts This error is back! Can you take a look?

  • Daniel.RDaniel.R USMember ✭✭

    Same error for me! I have a Image and a StackLayout, both with solid Colors from Hex(#277EC6).
    The image looks fine, but when i look at the screenshot, the StackLayout then has #2068B9.

  • JoshuaPolingJoshuaPoling USMember ✭✭

    I ran into this issue as well on Xamarin Looking into the CGColor class I found that the conversions Xamarin is using for the extension ToCGColor is incorrect. CGColors are between 1 and 0. You can create a custom renderer to set the value by dividing each rgb values by 255. Example
    Layer.BorderColor = new CoreGraphics.CGColor(255/255, 87 / 255, 31 / 255);

    Does anyone know if this bug has been filed or where I can find a list of active Xamarin Forms bugs?

    Best Regards,

  • DottorPagliacciusDottorPagliaccius ITMember ✭✭

    Thanks to @ChrisCastrianni, of course

  • LamarthLamarth AUMember

    My gradient renderer was faded - I got to the point where I realised it was the color space. I wouldn't have picked Srgb until my 5th or so try though - thanks Chris.Castrianni!

    But doesn't this issue affect everyone who tries to use ToCGColor?

Sign In or Register to comment.