2016-12-15 51 views

回答

2

第一店顏色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個串來獲得紅,綠,藍顏色代碼。

1

可以使用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,而不是一個評論,我沒有足夠多的聲望)

+1

正確,一個很好的stackoverflow後有關http://stackoverflow.com/questions/10310917/uicolor-from-hex-in-monotouch – OrcusZ

相關問題