代码之家  ›  专栏  ›  技术社区  ›  Swathy

如何在ios中创建多列表

  •  1
  • Swathy  · 技术社区  · 8 年前

    请帮帮我。。。

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

    1 回复  |  直到 8 年前
        1
  •  2
  •   ColeX    8 年前

    可以通过以下步骤模拟绘制图表。

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

    2. 执行与步骤1相同的操作 TableViewCell ,然后在第一个矩形中放置文本字段,在第二个矩形中放置按钮和标签,在第三个矩形中放置两个按钮。

    示例代码

    桌面视图

    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();
    

    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