Esempio n. 1
0
 public UICheckbox() : base()
 {
     this.falseImage = UIImageCache.GetUIImage("Images/checkbox.off.png");
     this.trueImage  = UIImageCache.GetUIImage("Images/checkbox.on.png");
     this.Image      = falseImage;
     this.Value      = false;
 }
Esempio n. 2
0
        public override UITableViewCell GetCell(UITableView tv)
        {
            // always create a new cell instead of dequeuing a proper cell - this is because
            // each ButtonListElement may have a different number of buttons and so will have different
            // subviews - therefore not recyclable
            var cell = new UITableViewCell(UITableViewCellStyle.Default, "ButtonListElementCell");

            cell.Accessory      = UITableViewCellAccessory.None;
            cell.SelectionStyle = UITableViewCellSelectionStyle.None;
            if (App.ViewModel.Theme == null)
            {
                cell.BackgroundColor = UIColor.FromPatternImage(UIImageCache.GetUIImage("Images/background.png"));
            }
            else
            {
                cell.BackgroundColor = UIColorHelper.FromString(App.ViewModel.Theme.PageBackground);
            }

            // if no child buttons, return a blank cell
            if (Buttons.Count == 0)
            {
                return(cell);
            }

            float margin  = Margin ?? defaultMargin;
            float spacing = margin > minSpacing ? margin : minSpacing;

            // compute button width:
            //   [margin] { [button] { [buttonspacing] [ button] }* [margin] }
            // the total available width is the bounds minus the margins and button spacing (minus 20 fudge factor
            // since CocoaTouch seems to pad the cell by 10 pixels on each side)
            // divide this available width by the number of buttons and deduct the margin
            // to get the button width
            float availableWidth = cell.Bounds.Width - 20f - 2 * margin - (Buttons.Count - 1) * spacing;
            float buttonWidth    = Convert.ToSingle(Math.Round(availableWidth / Buttons.Count));
            float buttonHeight   = (cell.Bounds.Height) - 2 * margin;

            int x = 0;

            foreach (var btn in Buttons)
            {
                UIButton button = UIButton.FromType(UIButtonType.RoundedRect);
                button.Frame = new RectangleF(margin + x * (buttonWidth + spacing), margin, buttonWidth, buttonHeight);
                button.SetTitle(btn.Caption, UIControlState.Normal);
                if (btn.Background != null)
                {
                    // set the background image, and also change the font color to white
                    button.SetBackgroundImage(UIImageCache.GetUIImage(btn.Background), UIControlState.Normal);
                    button.SetTitleColor(btn.TextColor ?? UIColor.White, UIControlState.Normal);
                    button.Font = btn.Font ?? UIFont.BoldSystemFontOfSize(17);
                }
                Button savedButton = btn;
                if (btn.Clicked != null)
                {
                    button.TouchUpInside += (s, e) => { savedButton.Clicked(savedButton, e); };
                }
                // retain a reference to the button (otherwise it somehow falls out of scope and gets GC'd
                // causing a SIGSEGV when the event handler is invoked)
                btn.ButtonReference = button;
                cell.ContentView.AddSubview(button);
                x++;
            }

            return(cell);
        }