Example #1
0
        public void CreateStepper(CGRect rect, string extraLabel)
        {
            UIView parent = GetParentView();

            WidgetType = UIVariable.UIType.STEPPER;
            UILabel label = null;

            int stepperX  = (int)(10 * UtilsiOS.WidthMultiplier());
            int stepperY  = (int)(4 * UtilsiOS.WidthMultiplier());
            int labelSize = (int)rect.Height;

            CGRect    stepRect = new CGRect(stepperX, stepperY, rect.Width, rect.Height);
            UIStepper stepper  = new UIStepper(stepRect);

            m_viewX = new UIView(rect);

            if (!string.IsNullOrWhiteSpace(extraLabel))
            {
                extraLabel = extraLabel.ToLower();
                nfloat labelWidth  = rect.Width - stepper.Bounds.Width;
                nfloat labelHeight = stepper.Bounds.Height;
                if (extraLabel.EndsWith("left"))
                {
                    stepperX = 0;
                    CGRect labelRect = new CGRect(stepperX, stepperY, labelWidth, labelHeight);
                    label = new UILabel(labelRect);
                    label.TextAlignment = UITextAlignment.Left;
                    stepRect            = new CGRect(stepperX + labelWidth, stepperY, stepper.Bounds.Width, stepper.Bounds.Height);
                    stepper             = new UIStepper(stepRect);
                }
                else
                {
                    CGRect labelRect = new CGRect(stepperX + stepper.Bounds.Width, stepperY, labelWidth, labelHeight);
                    label = new UILabel(labelRect);
                    label.TextAlignment = UITextAlignment.Right;
                }
                label.Text          = CurrVal.ToString();
                label.TextAlignment = UITextAlignment.Center;
                //label.SizeToFit();
                m_viewX.AddSubview(label);
            }
            // "5:3:50:1"
            double curr = 0, min = 0, max = 0, step = 0;

            Utils.Extract(extraLabel, ref curr, ref min, ref max, ref step);
            CurrVal = curr;
            MinVal  = min;
            MaxVal  = max;
            Step    = step;

            stepper.MinimumValue = (float)MinVal;
            stepper.MaximumValue = (float)MaxVal;
            stepper.Value        = (float)CurrVal;
            stepper.StepValue    = (float)Step;

            m_viewX.AddSubview(stepper);
            //m_viewY = stepper;

            stepper.ValueChanged += (sender, e) => {
                CurrVal = stepper.Value;
                if (label != null)
                {
                    label.Text = CurrVal.ToString();
                }
                ActionDelegate?.Invoke(WidgetName, CurrVal.ToString());
            };
        }