public ColorPickerHueGridViewController()
            : base()
        {
            _colors = new List <UIColor>();

            for (var i = 0; i < 12; i++)
            {
                var hue        = (float)(i * 30f / 360f);
                var colorCount = DisplayHelper.Is4InchDisplay() ? 32 : 24;

                for (var j = 0; j < colorCount; j++)
                {
                    var row    = j / 4;
                    var column = j % 4;

                    var saturation = (float)column * 0.25f + 0.25f;
                    var luminosity = 1f - (float)row * 0.12f;
                    var color      = UIColor.FromHSBA(hue, saturation, luminosity, 1f);
                    _colors.Add(color);
                }
            }
        }
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            this.View.BackgroundColor = UIColor.Clear;

            _colorBarView = new UIImageView(new RectangleF(10f, 10f, 300f, 30f))
            {
                Image = new UIImage("*****@*****.**")
            };

            this.View.AddSubview(_colorBarView);

            _paletteView = new UIScrollView(new RectangleF(0, 50f, 320f, this.View.Frame.Height - 120f))
            {
                BackgroundColor        = UIColor.Clear,
                Bounces                = true,
                AlwaysBounceHorizontal = true,
                AlwaysBounceVertical   = false,
                PagingEnabled          = true
            };

            this.View.AddSubview(_paletteView);

            var layer = new CALayer
            {
                Frame         = new RectangleF(130f, 16f, 100f, 40f),
                CornerRadius  = 6f,
                ShadowColor   = UIColor.Black.CGColor,
                ShadowOffset  = new SizeF(0f, 2f),
                ShadowOpacity = 0.8f
            };

            _paletteView.Layer.AddSublayer(layer);

            var index = 0;

            for (var i = 0; i < 12; i++)
            {
                var colorCount = DisplayHelper.Is4InchDisplay() ? 32 : 24;

                for (var j = 0; j < colorCount && index < _colors.Count; j++)
                {
                    var colorIndex = index++;
                    layer = new CALayer
                    {
                        Name            = $"Color_{colorIndex}",
                        CornerRadius    = 6f,
                        BackgroundColor = _colors[colorIndex].CGColor
                    };

                    var column = j % 4;
                    var row    = j / 4;
                    layer.Frame = new RectangleF(i * 320 + 8 + (column * 78), 8 + row * 48, 70f, 40f);
                    LayerHelper.SetupShadow(layer);
                    _paletteView.Layer.AddSublayer(layer);
                }
            }

            _paletteView.ContentSize = new SizeF(3840f, 296f);

            var colorRecognizer = new UITapGestureRecognizer(ColorGridTapped);

            _paletteView.AddGestureRecognizer(colorRecognizer);

            _colorBarView.UserInteractionEnabled = true;
            var barRecognizer = new UITapGestureRecognizer(ColorBarTapped);

            _colorBarView.AddGestureRecognizer(barRecognizer);
        }
Exemple #3
0
        private void SetSliders()
        {
            var y          = DisplayHelper.Is4InchDisplay() ? 40f : 35f;
            var sliderSize = new SizeF(320f - 135f, 20f);
            var sliderX    = 55f;

            _sliderR = new UISlider(new RectangleF(new PointF(sliderX, 270f), sliderSize))
            {
                MaxValue = 255,
                MinValue = 0,
                Value    = 255
            };
            _sliderR.ValueChanged += Slider_ValueChanged;
            this.View.AddSubview(_sliderR);

            _sliderG = new UISlider(new RectangleF(new PointF(sliderX, 270f + y), sliderSize))
            {
                MaxValue = 255,
                MinValue = 0
            };
            _sliderG.ValueChanged += Slider_ValueChanged;
            this.View.AddSubview(_sliderG);

            _sliderB = new UISlider(new RectangleF(new PointF(sliderX, 270f + (y * 2)), sliderSize))
            {
                MaxValue = 255,
                MinValue = 0
            };
            _sliderB.ValueChanged += Slider_ValueChanged;
            this.View.AddSubview(_sliderB);

            var labelX    = 40f;
            var labelSize = new SizeF(20f, 20f);

            var labelR = new UILabel(new RectangleF(new PointF(labelX, _sliderR.Frame.Y), labelSize))
            {
                Text      = "R",
                TextColor = UIColor.White
            };

            this.View.AddSubview(labelR);

            var labelG = new UILabel(new RectangleF(new PointF(labelX, _sliderG.Frame.Y), labelSize))
            {
                Text      = "G",
                TextColor = UIColor.White
            };

            this.View.AddSubview(labelG);

            var labelB = new UILabel(new RectangleF(new PointF(labelX, _sliderB.Frame.Y), labelSize))
            {
                Text      = "B",
                TextColor = UIColor.White
            };

            this.View.AddSubview(labelB);

            var labelValueX    = sliderSize.Width + 65f;
            var labelValueSize = new SizeF(40f, 20f);

            _labelRValue = new UILabel(new RectangleF(new PointF(labelValueX, _sliderR.Frame.Y), labelValueSize))
            {
                Text      = "255",
                TextColor = UIColor.White
            };
            this.View.AddSubview(_labelRValue);

            _labelGValue = new UILabel(new RectangleF(new PointF(labelValueX, _sliderG.Frame.Y), labelValueSize))
            {
                Text      = "0",
                TextColor = UIColor.White
            };
            this.View.AddSubview(_labelGValue);

            _labelBValue = new UILabel(new RectangleF(new PointF(labelValueX, _sliderB.Frame.Y), labelValueSize))
            {
                Text      = "0",
                TextColor = UIColor.White
            };
            this.View.AddSubview(_labelBValue);
        }