Created
March 19, 2019 21:10
-
-
Save wcoder/de1b26b050ff5d31576c68b416102f95 to your computer and use it in GitHub Desktop.
Port of UIColorMSHashExtension from Swift to C#. Office UI Fabric iOS for Xamarin.iOS
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using UIKit; | |
namespace XamarinOfficeUIFabric | |
{ | |
public static class ColorExtensions | |
{ | |
// Original MS Source: | |
// https://github.com/OfficeDev/office-ui-fabric-ios/blob/master/OfficeUIFabricCore/OfficeUIFabricCore/Core/Colors/UIColorMSHashExtension.swift | |
public static UIColor MSHashColor(this string hash) | |
{ | |
var randomNum = 3074457345618258791; | |
var rgbRed = new nfloat[] { 0, 8, 16, 136, 180, 232, 218, 0, 0, 0, 168, 78 }; | |
var rgbGreen = new nfloat[] { 120, 130, 124, 23, 0, 17, 59, 111, 94, 78, 0, 37 }; | |
var rgbBlue = new nfloat[] { 215, 114, 16, 152, 158, 35, 1, 148, 80, 140, 0, 127 }; | |
foreach (var c in hash) | |
{ | |
randomNum = randomNum + c; | |
randomNum = randomNum * 3074457345618258799; | |
} | |
var index = randomNum % rgbBlue.Length; | |
return UIColor.FromRGBA( | |
red: rgbRed[index] / 255, | |
green: rgbGreen[index] / 255, | |
blue: rgbBlue[index] / 255, | |
alpha: 1); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment