Example #1
0
 public void SetCheckState(CheckboxState checkState)
 {
     CheckState = checkState;
     if (CheckedChanged != null)
     {
         CheckedChanged(this, new CheckedChangedEventArgs(CheckState == CheckboxState.Checked));
     }
     CheckView.SetNeedsDisplay();
 }
Example #2
0
        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();
        }
Example #3
0
        //        - (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);
            //StrokeColor = UIColor.FromRGBA(255, 255, 255, 255);

            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);
            //TintColor = UIColor.FromRGBA(255, 255 ,255,255);
            UncheckedColor  = UIColor.FromRGBA(0, 0, 0, 0);
            ClipsToBounds   = false;
            BackgroundColor = UIColor.Clear;

            //Color = Color.FromHex("#ce1e21").ToUIColor();
            Radius         = Constants.BoxRadius * heightForCheckbox;
            CheckAlignment = CheckboxAlignment.Right;
            CheckState     = CheckboxState.Unchecked;
            SetTitleColor(UIColor.Black, UIControlState.Normal);
            Enabled = true;
            //HorizontalAlignment = UIControlContentHorizontalAlignment.Center;

            // 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(50);
            TitleLabel.LineBreakMode          = UILineBreakMode.TailTruncation;
            TitleLabel.BackgroundColor        = UIColor.Clear;
            TitleLabel.UserInteractionEnabled = false;
            ContentEdgeInsets                 = new UIEdgeInsets(0, 30, 0, 0);
            LayoutMargins = new UIEdgeInsets(20, 0, 0, 0);
            AddGestureRecognizer(new UITapGestureRecognizer(ToggleCheckState));

            AutoFitFontToHeight();
            AddSubview(CheckView);
            //AddSubview(TitleLabel);
            LayoutSubviews();
        }