Monotouch中来自Hex的UIColor [英] UIColor from Hex in Monotouch

查看:20
本文介绍了Monotouch中来自Hex的UIColor的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

How to get a UIColor from an hex value in Monotouch?

解决方案

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)
            );
        }
    }

and use it like this:

new UIColor().FromHex(0x4F6176);

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中来自Hex的UIColor的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆