UILabel label = new UILabel();
label.TextColor = UIColor.Black;
如何以字符串格式存儲UILabel顏色?我想從數據庫中獲取該顏色並應用於UILabel。如何使用C#將UIColor轉換爲字符串和字符串爲UIColor?如何從UIColor轉換爲字符串和字符串爲Xamarin.Ios中的UIColor使用c#
在此先感謝!
UILabel label = new UILabel();
label.TextColor = UIColor.Black;
如何以字符串格式存儲UILabel顏色?我想從數據庫中獲取該顏色並應用於UILabel。如何使用C#將UIColor轉換爲字符串和字符串爲UIColor?如何從UIColor轉換爲字符串和字符串爲Xamarin.Ios中的UIColor使用c#
在此先感謝!
第一店顏色DB作爲的UIColor這樣
string color = yourBtn.BackgroundColor.ToString();
那麼你的顏色轉換的UIColor作爲
string hex = color.;
nfloat red = Convert.ToInt32(string.Format("{0}{0}",hex.Substring(0, 1)), 16)/255f;
nfloat green = Convert.ToInt32(string.Format("{0}{0}",hex.Substring(1, 1)), 16)/255f;
nfloat blue = Convert.ToInt32(string.Format("{0}{0}",hex.Substring(2, 1)), 16)/255f;
UIColor color = UIColor.FromRGB(red, green, blue);
需要字符串分割到3個串來獲得紅,綠,藍顏色代碼。
可以使用8char的十六進制顏色格式(如#ff0a11ff)
當加載/保存字符串,只需解析成一個字節數組或一個int數組,如UILabel.FromRGBA允許您創建從他們的顏色:https://developer.xamarin.com/api/member/MonoTouch.UIKit.UIColor.FromRGBA/p/System.Int32/System.Int32/System.Int32/System.Int32/
(抱歉給一個anwser,而不是一個評論,我沒有足夠多的聲望)
正確,一個很好的stackoverflow後有關http://stackoverflow.com/questions/10310917/uicolor-from-hex-in-monotouch – OrcusZ