Пример #1
0
        public IconiOSCell(string cellId, IconTextCell cell) : base(UITableViewCellStyle.Default, cellId)
        {
            NativeCell = cell;

            SelectionStyle = cell.SelectionStyle.ToiOSSelectionStyle();

            var code = cell.IconCode; // Icon code is mapped by a converter further up the chain. It is managed by binding from the cell factory.

            if (!string.IsNullOrWhiteSpace(code))
            {
                IconImage = new UIImageView(UIImage.FromFile(code));
            }
            else
            {
                IconImage = new UIImageView();
            }

            TextContainer      = new UIStackView();
            TextContainer.Axis = UILayoutConstraintAxis.Vertical;
            TextContainer.TranslatesAutoresizingMaskIntoConstraints = false;
            TextContainer.Alignment = UIStackViewAlignment.Fill;

            HeadingLabel = new UILabel()
            {
                BackgroundColor = UIColor.Clear,
                TextColor       = UIColor.Black,
                Font            = UIFont.PreferredBody,
            };

            DetailLabel = new UILabel()
            {
                BackgroundColor = UIColor.Clear,
                TextColor       = UIColor.Black,
                Font            = UIFont.PreferredSubheadline,
            };

            ContentView.Add(IconImage);
            ContentView.Add(TextContainer);
            TextContainer.AddArrangedSubview(HeadingLabel);

            if (cell.DisplayMode != Redbridge.Forms.ViewModels.Cells.IconCellViewMode.TitleOnly)
            {
                TextContainer.AddArrangedSubview(DetailLabel);
            }

            switch (cell.CellHeight)
            {
            case TableCellHeight.Large:
                IconImage.AddWidthAndHeightConstraints(32, 32);
                this.AddLeftConstraint(IconImage, 15);
                break;

            case TableCellHeight.Medium:
                IconImage.AddWidthAndHeightConstraints(24, 24);
                this.AddLeftConstraint(IconImage, 10);
                break;

            default:
                IconImage.AddWidthAndHeightConstraints(16, 16);
                this.AddLeftConstraint(IconImage, 5);
                break;
            }

            this.AddVerticalAlignmentConstraint(IconImage);
            this.AddVerticalAlignmentConstraint(TextContainer);
            this.AddLeftMarginConstraintBetween(IconImage, TextContainer, 5);

            HeadingLabel.AddHeightConstraint(16);
            DetailLabel.AddHeightConstraint(16);
        }