gpt4 book ai didi

c# - 如何使用 c# 在 Xamarin.Ios 中将 UIColor 转换为字符串和将字符串转换为 UIColor

转载 作者:行者123 更新时间:2023-11-28 19:33:53 25 4
gpt4 key购买 nike

UILabel label = new UILabel();

label.TextColor = UIColor.Black;

如何以字符串格式存储 UILabel 颜色?我想从数据库中获取该颜色并应用于 UILabel。如何使用 C# 将 UIColor 转换为字符串以及将字符串转换为 UIColor?

提前致谢!

最佳答案

首先像这样将颜色作为 UIColor 存储在数据库中

 string color = yourBtn.BackgroundColor.ToString();

然后将你的颜色转换为 UIColor as

 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 个子字符串以获得红色、绿色、蓝色颜色代码。

关于c# - 如何使用 c# 在 Xamarin.Ios 中将 UIColor 转换为字符串和将字符串转换为 UIColor,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41161997/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com