Monotouch中十六进制的UIColor [英] UIColor from Hex in Monotouch
本文介绍了Monotouch中十六进制的UIColor的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何从 Monotouch 中的十六进制值获取 UIColor?
How to get a UIColor from an hex value in Monotouch?
推荐答案
我找到了一些针对 Objective C 的解决方案,但没有专门针对 Monotouch 我最终开发了一种基于最流行的 IOS 解决方案的扩展方法:
I found some solutions for Objective C and none specifically for Monotouch I ended up developing an extension method based on the most popular solution for IOS:
public static class UIColorExtensions
{
public static UIColor FromHex(this UIColor color,int hexValue)
{
return UIColor.FromRGB(
(((float)((hexValue & 0xFF0000) >> 16))/255.0f),
(((float)((hexValue & 0xFF00) >> 8))/255.0f),
(((float)(hexValue & 0xFF))/255.0f)
);
}
}
并像这样使用它:
new UIColor().FromHex(0x4F6176);
更新,似乎 Monotouch 5.4 UIColor 没有无参数构造函数,所以像这样使用它:
Update, it seems that as off Monotouch 5.4 UIColor does not have a parameterless constructor so use it like this:
UIColor.Clear.FromHex(0xD12229);
这篇关于Monotouch中十六进制的UIColor的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文