iOS逻辑 - 添加使用适当坐标编程构建的顺序子视图



原始标题:iOS逻辑 - 在xamarin中添加带有其子元素的视图

我不确定该问题如何,所以我会尽力而为。

您知道像Groupon这样的应用程序如何列出其报价?或Facebook应用程序如何在Minifeed中动态生产部分 - 包含子元素的正方形,例如配置文件图像视图,名称,发布内容等。

是什么逻辑?

我尝试做的是将内容视图放在设计师中,并在此内容视图部分中列出我想要的元素,然后从设计师中的视图中使用子元素来编程中的内容视图。这是适当的方法吗?有人可以以实现这一目标的标准逻辑来启发我?

编辑:

我弄清楚我真正想问的是:构建子视图的最佳方法是什么(包括图像,标签,文本菲尔德等),以编程方式,然后动态添加的副本它 - 下一个下方 - 滚动浏览。

您可能应该使用UITATIONVIEW和/或UICOLLECTIONVIEW托管视图。

,所以我弄清楚了我要做什么,请添加一个视图。我通过将其在设计师中并从那里获取坐标来弄清楚元素应在何处的尺寸。我创建了一个自定义Uiview类:

public class FestivalSquareView : UIView
{
    public UIImageView festivalImage { get; set; }
    public UILabel nameLabel { get; set; }
    public UILabel locationLabel { get; set; }
    public UILabel dateLabel { get; set; }
    public UITextView descriptionText { get; set; }
    public static int HEIGHT = 270;
    public FestivalSquareView ()
    {
    }
    public FestivalSquareView (string image, string name, string location,
                               string date, string description)
    {
        setImage (image);
        setName (name);
        setLocation (location);
        setDate (date);
        setDescription (description);
    }
    public void setImage(string imageLoc)
    {
        festivalImage = new UIImageView (new RectangleF (0, 0, 320, 177));
        festivalImage.Image = UIImage.FromFile (imageLoc);
    }
    public void setName(string name)
    {
        nameLabel = new UILabel(new RectangleF(20,129,150,21));
        nameLabel.Text = name;  
        nameLabel.Font = UIFont.FromName("Helvetica", 15f);
        nameLabel.TextColor = UIColor.White;    
    }
    public void setLocation(string location)
    {
        locationLabel = new UILabel(new RectangleF(20,148,100,21));
        locationLabel.Text = location;  
        locationLabel.Font = UIFont.FromName("Helvetica", 13f);
        locationLabel.TextColor = UIColor.White;    
    }  
    public void setDate(string date)
    {
        dateLabel = new UILabel (new RectangleF (195, 148, 105, 21));
        dateLabel.Text = date;
        dateLabel.TextColor = UIColor.White;
        dateLabel.Font = UIFont.FromName("Helvetica", 13f);
        dateLabel.TextAlignment = UITextAlignment.Right;
    }
    public void setDescription(string description)
    {
        descriptionText = new UITextView (new RectangleF (20, 185, 280, 75));
        descriptionText.Text = description;
    }
    public void buildView(float y)
    {
        this.Frame = new RectangleF (0, y, 320, 270);
        this.AddSubview (festivalImage);
        this.AddSubview (nameLabel);
        this.AddSubview (locationLabel);
        this.AddSubview (dateLabel);
        this.AddSubview (descriptionText);
    }

}

我使用设计器将滚动视图放入我的ViewController中,将其连接,在上面构造了我的自定义Uiview,将Y Cooardinate设置在buildView中,并将其添加到ScrollView

,然后我使用

计算了下一个y坐标
next.buildView (prev.Frame.Y + prev.Frame.Size.Height);
festivalScrollView.AddSubView(next);

相关内容

最新更新