Как создать таблицу с несколькими столбцами в IOS - PullRequest
0 голосов
/ 24 мая 2018

Я новичок в xamarin ios, я хочу создать таблицу с 3 столбцами и несколькими строками, и количество строк зависит от данных, поступающих из API. Как я могу это сделать ...

Пожалуйста, помогите мне ...

Я хочу создать такую ​​таблицу ... enter image description here

1 Ответ

0 голосов
/ 25 мая 2018

Вы можете смоделировать рисование диаграммы, выполнив следующие шаги.

  1. Пользовательский TableHeaderView с тремя черными прямоугольниками, просто нужно добавить три метки с черной рамкой.

  2. Выполните ту же работу, что и шаг1, с TableViewCell, затем поместите текстовое поле в первый прямоугольник, поместите кнопку и метку во второй прямоугольник, поместите две кнопки в третий прямоугольник.

Пример кода

TableHeaderView

public class headerView : UIView
{
    public headerView()
    {
        this.Frame = new CGRect(0, 0, UIScreen.MainScreen.Bounds.Width, 50);

        nfloat width = UIScreen.MainScreen.Bounds.Width / 3;

        UILabel title = new UILabel();
        title.Text = "Title";
        title.TextColor = UIColor.Black;
        title.TextAlignment = UITextAlignment.Center;
        title.Font = UIFont.SystemFontOfSize(20);
        title.Layer.BorderColor = UIColor.Black.CGColor;
        title.Layer.BorderWidth = 1;
        title.Frame = new CGRect(0, 0, width, 50);
        this.Add(title);

        UILabel File = new UILabel();
        File.Text = "File";
        File.TextColor = UIColor.Black;
        File.TextAlignment = UITextAlignment.Center;
        File.Font = UIFont.SystemFontOfSize(20);
        File.Layer.BorderColor = UIColor.Black.CGColor;
        File.Layer.BorderWidth = 1;
        File.Frame = new CGRect(width, 0, UIScreen.MainScreen.Bounds.Width / 3, 50);
        this.Add(File);

        UILabel Option = new UILabel();
        Option.Text = "Option";
        Option.TextColor = UIColor.Black;
        Option.TextAlignment = UITextAlignment.Center;
        Option.Font = UIFont.SystemFontOfSize(20);
        Option.Layer.BorderColor = UIColor.Black.CGColor;
        Option.Layer.BorderWidth = 1;
        Option.Frame = new CGRect(width * 2, 0, UIScreen.MainScreen.Bounds.Width / 3, 50);
        this.Add(Option);
    }
}

table.TableHeaderView = new headerView();

TableViewCell

public CustomVegeCell (NSString cellId) : base (UITableViewCellStyle.Default, cellId)
    {
        SelectionStyle = UITableViewCellSelectionStyle.Gray;

        nfloat width = UIScreen.MainScreen.Bounds.Width / 3;

        UIView headingLabel = new UIView();
        headingLabel.Layer.BorderColor = UIColor.Black.CGColor;
        headingLabel.Layer.BorderWidth = 1;
        headingLabel.Frame = new CGRect(0, 0, width, 100);


        UIView subheadingLabel = new UIView();
        subheadingLabel.Layer.BorderColor = UIColor.Black.CGColor;
        subheadingLabel.Layer.BorderWidth = 1;
        subheadingLabel.Frame = new CGRect(width, 0, width, 100);

        UIView imageView = new UIView();
        imageView.Layer.BorderColor = UIColor.Black.CGColor;
        imageView.Layer.BorderWidth = 1;
        imageView.Frame = new CGRect(width *2, 0, width, 100);

        ContentView.Add (headingLabel);
        ContentView.Add (subheadingLabel);
        ContentView.Add (imageView);

        ///add additional control here
    }

enter image description here

...