Exemple #1
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));
            _sliderR.MaxValue      = 255;
            _sliderR.MinValue      = 0;
            _sliderR.Value         = 255;
            _sliderR.ValueChanged += Slider_ValueChanged;
            this.View.AddSubview(_sliderR);

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

            _sliderB               = new UISlider(new RectangleF(new PointF(sliderX, 270f + (y * 2)), sliderSize));
            _sliderB.MaxValue      = 255;
            _sliderB.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));

            labelR.Text      = "R";
            labelR.TextColor = UIColor.White;
            this.View.AddSubview(labelR);

            var labelG = new UILabel(new RectangleF(new PointF(labelX, _sliderG.Frame.Y), labelSize));

            labelG.Text      = "G";
            labelG.TextColor = UIColor.White;
            this.View.AddSubview(labelG);

            var labelB = new UILabel(new RectangleF(new PointF(labelX, _sliderB.Frame.Y), labelSize));

            labelB.Text      = "B";
            labelB.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));
            _labelRValue.Text      = "255";
            _labelRValue.TextColor = UIColor.White;
            this.View.AddSubview(_labelRValue);

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

            _labelBValue           = new UILabel(new RectangleF(new PointF(labelValueX, _sliderB.Frame.Y), labelValueSize));
            _labelBValue.Text      = "0";
            _labelBValue.TextColor = UIColor.White;
            this.View.AddSubview(_labelBValue);
        }
Exemple #2
0
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            View.BackgroundColor = UIColor.Clear;

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

            View.AddSubview(_colorBarView);

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

            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();
                    layer.Name            = $"Color_{colorIndex}";
                    layer.CornerRadius    = 6f;
                    layer.BackgroundColor = _colors[colorIndex].CGColor;

                    var column = j % 4;
                    var row    = j / 4;
                    layer.Frame = new RectangleF((float)(i * 320 + 8 + (column * 78)), (float)(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);
        }