如何在ios中创建包含多个列的表

时间:2018-05-24 10:15:34

标签: c# xamarin.ios storyboard viewcontroller tablelayout

我是xamarin ios的初学者,我想创建一个包含3列和多行的表,而行的no取决于来自API的数据。我怎么能这样做......

请帮帮我......

我想创建这样的表格...... enter image description here

1 个答案:

答案 0 :(得分:2)

您可以按照以下步骤模拟绘制图表。

  1. 自定义TableHeaderView有三个黑色矩形,只需添加三个带黑色边框的标签。

  2. 使用TableViewCell执行与step1相同的工作,然后将文本字段放在第一个矩形中,在第二个矩形中放置一个按钮和一个标签,在第三个矩形中放置两个按钮。

    < / LI>

    示例代码

    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

相关问题