public void SetCheckState(CheckboxState checkState)
 {
     CheckState = checkState;
     if (CheckedChanged != null)
     {
         CheckedChanged(this, new CheckedChangedEventArgs(CheckState == CheckboxState.Checked));
     }
     CheckView.SetNeedsDisplay();
 }
        //        - (id)initWithTitle:(NSString *)title
        //        {
        //            self = [self initWithFrame:CGRectMake(0, 0, 100.0, M13CheckboxDefaultHeight) title:title checkHeight:M13CheckboxDefaultHeight];
        //            if (self) {
        //                CGSize labelSize;
        //                if ([title respondsToSelector:@selector(sizeWithAttributes:)]) {
        //                    labelSize = [title sizeWithAttributes:@{ NSFontAttributeName: _titleLabel.font }];
        //                } else {
        //
        //                    NSDictionary *attributes = @{NSFontAttributeName: _titleLabel.font};
        //                    labelSize = [_titleLabel.text sizeWithAttributes:attributes];
        //                    labelSize =CGSizeMake(ceilf(labelSize.width), ceilf(labelSize.height));
        //
        //                }
        //
        //                self.frame = CGRectMake(
        //                    self.frame.origin.x,
        //                    self.frame.origin.y,
        //                    labelSize.width + ([self heightForCheckbox] * kCheckBoxSpacing) + ((kBoxSize + kCheckHorizontalExtention) * [self heightForCheckbox]),
        //                    self.frame.size.height);
        //            }
        //            return self;
        //        }

        //        - (id)initWithFrame:(CGRect)frame title:(NSString *)title
        //        {
        //            self = [self initWithFrame:frame title:title checkHeight:M13CheckboxDefaultHeight];
        //            if (self) {
        //
        //            }
        //            return self;
        //        }

        //        - (id)initWithFrame:(CGRect)frame title:(NSString *)title checkHeight:(CGFloat)checkHeight
        //        {
        //            self = [super initWithFrame:frame];
        //            if (self) {
        //                //Set the title label text
        //                _checkHeight = checkHeight;
        //                [self setup];
        //                _titleLabel.text = title;
        //                [self layoutSubviews];
        //            }
        //            return self;
        //        }

        void Setup()
        {
            // Set the basic properties
            var heightForCheckbox = HeightForCheckbox();

            //Flat = true;
            StrokeColor     = UIColor.FromRGBA((System.nfloat) 0.02, (System.nfloat) 0.47, (System.nfloat) 1.0, (System.nfloat) 1.0);
            StrokeWidth     = Constants.BoxStrokeWidth * heightForCheckbox;
            CheckColor      = UIColor.FromRGBA((System.nfloat) 0.02, (System.nfloat) 0.47, (System.nfloat) 1.0, (System.nfloat) 1.0);
            TintColor       = UIColor.FromRGBA((System.nfloat) 1.0, (System.nfloat) 1.0, (System.nfloat) 1.0, (System.nfloat) 1.0);
            UncheckedColor  = UIColor.FromRGBA(0, 0, 0, 0);
            ClipsToBounds   = false;
            BackgroundColor = UIColor.Clear;
            Radius          = Constants.BoxRadius * heightForCheckbox;
            CheckAlignment  = CheckboxAlignment.Right;
            CheckState      = CheckboxState.Unchecked;
            Enabled         = true;

            // Create the check view
            var checkViewFrame = new CGRect(
                Frame.Size.Width - ((Constants.BoxSize + Constants.CheckHorizontalExtention) * heightForCheckbox),
                (Frame.Size.Height - ((Constants.BoxSize + Constants.CheckHorizontalExtention) * heightForCheckbox)) / (System.nfloat) 2.0,
                ((Constants.BoxSize + Constants.CheckHorizontalExtention) * heightForCheckbox),
                heightForCheckbox)
                                 .Integral();

            CheckView                        = new CheckView(checkViewFrame);
            CheckView.Checkbox               = this;
            CheckView.Selected               = false;
            CheckView.BackgroundColor        = UIColor.Clear;
            CheckView.ClipsToBounds          = false;
            CheckView.UserInteractionEnabled = false;

            // Create the title label
            CGRect labelFrame = new CGRect(
                0,
                0,
                Frame.Size.Width - CheckView.Frame.Size.Width - (heightForCheckbox * Constants.CheckBoxSpacing),
                Frame.Size.Height)
                                .Integral();

            TitleLabel                        = new UILabel(labelFrame);
            TitleLabel.Text                   = "";
            TitleLabel.TextColor              = UIColor.FromRGBA(0, 0, 0, 1);
            TitleLabel.Font                   = UIFont.BoldSystemFontOfSize(16);
            TitleLabel.LineBreakMode          = UILineBreakMode.TailTruncation;
            TitleLabel.BackgroundColor        = UIColor.Clear;
            TitleLabel.UserInteractionEnabled = false;

            AddGestureRecognizer(new UITapGestureRecognizer(ToggleCheckState));

            AutoFitFontToHeight();
            AddSubview(CheckView);
            AddSubview(TitleLabel);
            LayoutSubviews();
        }
        public void SetEnabled(bool enabled)
        {
            if (enabled)
            {
                TitleLabel.TextColor = LabelColor;
            }
            else
            {
                LabelColor = TitleLabel.TextColor;

                nfloat r, g, b, a;
                LabelColor.GetRGBA(out r, out g, out b, out a);
                r = NMath.Floor((nfloat)(r * 100.0 + 0.5)) / (nfloat)100.0;
                g = NMath.Floor((nfloat)(g * 100.0 + 0.5)) / (nfloat)100.0;
                b = NMath.Floor((nfloat)(b * 100.0 + 0.5)) / (nfloat)100.0;
                TitleLabel.TextColor = UIColor.FromRGBA(
                    (r + (nfloat)0.4),
                    (g + (nfloat)0.4),
                    (b + (nfloat)0.4),
                    (nfloat)1);
            }
            Enabled = enabled;
            CheckView.SetNeedsDisplay();
        }