public static UIKit.UIColor FromHex(string hexString)
        {
            hexString = hexString.ToUpper();
            var hex = hexString.StartsWith("#") ? hexString.Remove(0, 1) : hexString;

            int value = Int32.Parse(hex, System.Globalization.NumberStyles.HexNumber);

            UIKit.UIColor color = null;
            if (hex.Length == 8)
            {
                var alpha = (nfloat)(((value & 0xFF000000) >> 24) / 255.0);
                var red   = (nfloat)(((value & 0x00FF0000) >> 16) / 255.0);
                var green = (nfloat)(((value & 0x0000FF00) >> 8) / 255.0);
                var blue  = (nfloat)(((value & 0x000000FF)) / 255.0);
                color = new UIKit.UIColor(red, green, blue, alpha);
            }
            if (hex.Length == 6)
            {
                var red   = (nfloat)(((value & 0xFF0000) >> 16) / 255.0);
                var green = (nfloat)(((value & 0x00FF00) >> 8) / 255.0);
                var blue  = (nfloat)((value & 0x0000FF) / 255.0);
                color = new UIKit.UIColor(red, green, blue, 1.0f);
            }
            return(color);
        }
Exemple #2
0
        public static Color GetColor(this UIKit.UIColor color)
        {
            nfloat r, g, b, a;

            color.GetRGBA(out r, out g, out b, out a);
            return(Color.FromRGB(r, g, b, a));
        }
Exemple #3
0
        public static UNColor FromRgba(nfloat red, nfloat green, nfloat blue, nfloat alpha)
        {
#if __IOS__
            return(UNColor.FromRGBA(red, green, blue, alpha));
#else
            return(UNColor.FromRgba(red, green, blue, alpha));
#endif
        }
Exemple #4
0
        public static uint UIColorToInt(UIKit.UIColor color)
        {
            nfloat colorR, colorG, colorB, colorA;

            color.GetRGBA(out colorR, out colorG, out colorB, out colorA);

            return((uint)(colorR * 255.0f) << 24 | (uint)(colorG * 255.0f) << 16 | (uint)(colorB * 255.0f) << 8 | (uint)(colorA * 255.0f));
        }
Exemple #5
0
        public static RGB ToRGB(this UIKit.UIColor color)
        {
            nfloat r, g, b, a;

            color.GetRGBA(out r, out g, out b, out a);
            return(new RGB((byte)Math.Round(r * 255),
                           (byte)Math.Round(g * 255),
                           (byte)Math.Round(b * 255),
                           (byte)Math.Round(a * 255)));
        }
        NativeColor ToNativeColor(Color color)
        {
#if __IOS__
            return(NativeColor.FromRGBA(
                       color.Red,
                       color.Green,
                       color.Blue,
                       color.Alpha));
#elif MONOMAC
            return(NativeColor.FromDeviceRgba(
                       color.RedValue,
                       color.GreenValue,
                       color.BlueValue,
                       color.AlphaValue));
#endif
        }
        public override UIKit.UITableViewCell GetCell(Cell item, UIKit.UITableViewCell reusableCell, UIKit.UITableView tv)
        {
            tv.AllowsSelection = false;
            var cell = base.GetCell(item, reusableCell, tv);

            UIKit.UIColor backColor = Xamarin.Forms.Color.Transparent.ToUIColor();

            var cellEx = item as ViewCellEx;

            if (cellEx != null)
            {
                backColor = cellEx.CellBackColor.ToUIColor();
            }

            cell.BackgroundColor = backColor;

            if (_bgView == null)
            {
                _bgView = new UIKit.UIView
                {
                    BackgroundColor = backColor
                };
            }
            cell.BackgroundView = _bgView;

            cell.SelectionStyle = UIKit.UITableViewCellSelectionStyle.None;
            switch (item.StyleId)
            {
            case "checkmark":
                cell.Accessory = UIKit.UITableViewCellAccessory.Checkmark;
                break;

            case "detail-button":
                cell.Accessory = UIKit.UITableViewCellAccessory.DetailButton;
                break;

            case "detail-disclosure-button":
                cell.Accessory = UIKit.UITableViewCellAccessory.DetailDisclosureButton;
                break;

            case "disclosure":
            default:
                cell.Accessory = UIKit.UITableViewCellAccessory.None;
                break;
            }
            return(cell);
        }
        void SetUnderline()
        {
#if __IOS__
            var color = NativeColor.FromRGBA(
                underlineColor.Red,
                underlineColor.Green,
                underlineColor.Blue,
                underlineColor.Alpha);
            attrs.UnderlineColor = color;
            attrs.UnderlineStyle = underlineStyle == UnderlineStyle.None ?
                                   NSUnderlineStyle.None : NSUnderlineStyle.Single;
#elif MONOMAC
            attrs.Dictionary.SetValue(AppKit.NSStringAttributeKey.UnderlineColor, ToNativeColor(underlineColor));
            var ns = underlineStyle == UnderlineStyle.None ? 0 :
                     (underlineStyle == UnderlineStyle.Single ? 0x1 : 0x9);
            attrs.Dictionary.SetValue(AppKit.NSStringAttributeKey.UnderlineStyle, NSNumber.FromInt32(ns));
#endif
        }
        INativeObject ToNativeColor(Color color)
        {
            if (UseCGColor)
            {
                return(new CGColor(
                           color.RedValue,
                           color.GreenValue,
                           color.BlueValue,
                           color.AlphaValue));
            }
#if __IOS__
            return(NativeColor.FromRGBA(
                       color.Red,
                       color.Green,
                       color.Blue,
                       color.Alpha));
#elif MONOMAC
            return(NativeColor.FromDeviceRgba(
                       color.RedValue,
                       color.GreenValue,
                       color.BlueValue,
                       color.AlphaValue));
#endif
        }
 public static void RoundCorners(this _View thisButton, float radius = 2, float borderThickness = 0, _Color borderColor = null)
 {
     thisButton.AddBorder(borderThickness, borderColor);
     thisButton.Layer.CornerRadius = radius;
 }
 public static void AddBorder(this _View thisButton, float borderThickness = 1, _Color borderColor = null)
 {
     if (borderColor != null)
     {
         thisButton.Layer.BorderColor = borderColor.CGColor;
     }
     if (borderThickness > 0)
     {
         if (Math.Abs(borderThickness - 1f) < float.Epsilon && ViewHelper.IsRetinaDisplay)
         {
             borderThickness = (float)ViewHelper.OnePixel;
         }
         thisButton.Layer.BorderWidth = borderThickness;
     }
 }
Exemple #12
0
 public static FrameworkElement Background(this FrameworkElement panel, GenericColor color)
 {
     panel.Background = new SolidColorBrush(color);
     return(panel);
 }
Exemple #13
0
 public ChartColor(UIKit.UIColor value)
 {
     Value = value;
 }
Exemple #14
0
 public ChartColor(SkiaSharp.SKColor value)
 {
     Value = value;
 }
Exemple #15
0
 public ChartColor(double r, double g, double b, double a)
 {
     Value = new UIKit.UIColor((float)r, (float)g, (float)b, (float)a);
 }
        public static void AddBorder(this _View thisButton, float borderThickness = 1, _Color borderColor = null)
        {
            var layer = thisButton.Layer;

            if (borderColor != null)
            {
                layer.BorderColor = borderColor.CGColor;
            }
            if (borderThickness > 0)
            {
                layer.BorderWidth = ViewHelper.GetConvertedPixel(borderThickness);
            }
        }