c# - Whenever I call the class, I always get the same return of UIColor.White instead of whatever color I request -


i trying make class holds relevant data various graphical decisions make our app, , able make changes in 1 location. however, whenever call class, same return of uicolor.white instead of whatever color request. have class in xamarin.ios library reference in main project.

here code sample:

public static class mycolors {     public static uicolor backgroundcolor     {         { return converthextocolor("fa0000"); }     }      public static uicolor converthextocolor(string hex)     {         if (hex.contains('#')) hex.replace("#", "");         int[] rgba = new int[] { 255, 255, 255, 255 };          if (hex.length == 6)         {             rgba[0] = convert.toint32(hex.substring(0, 2), 16);             rgba[1] = convert.toint32(hex.substring(2, 2), 16);             rgba[2] = convert.toint32(hex.substring(4, 2), 16);         }         else if (hex.length == 8)         {             rgba[0] = convert.toint32(hex.substring(0, 2), 16);             rgba[1] = convert.toint32(hex.substring(2, 2), 16);             rgba[2] = convert.toint32(hex.substring(4, 2), 16);             rgba[3] = convert.toint32(hex.substring(6, 2), 16);         }         else         {             throw new argumentexception("hash must color code 6 or 8 characters in length.");         }          return new uicolor(rgba[0], rgba[1], rgba[2], rgba[3]);     }  } 

that's because uicolor constructor accepts 4 (4) system.single (float) values needs between 0.0f , 1.0f - considered 1.0f.

if want use byte or int use static fromrgba helper method.


Comments