【问题标题】:How to add footer to Flyout Drawer in Xamarin.Ios?如何在 Xamarin.Ios 中向 Flyout Drawer 添加页脚?
【发布时间】:2019-12-14 07:51:24
【问题描述】:

我正在尝试为 Native Xamarin.ios 的 Flyout Drawer 添加页脚。

要求类似于这两个Android问题,只是我需要为iOS原生完成:

How to add footer to NavigationView - Android support design library?

Add footer layout in navigation drawer

public class FlyoutDrawerMenuTableView : UITableViewController
{
    public override void ViewDidLoad()
    {
        base.ViewDidLoad();

        this.TableView.RegisterClassForCellReuse(typeof(UITableViewVibrantCell), "VibrantCell");
    }

    public override nint RowsInSection(UITableView tableView, nint section)
    {
        return 4;
    }

    public override UITableViewCell GetCell(UITableView tableView, Foundation.NSIndexPath indexPath)
    {
        var cell = tableView.DequeueReusableCell("VibrantCell");
        cell.TextLabel.TextColor = UIColor.White;

        switch (indexPath.Row)
        {
            case 0:
                cell.TextLabel.Text = "Home";
                cell.ImageView.Image = UIImage.FromBundle("home.png");
                break;
            case 1:
                cell.TextLabel.Text = "Preferences";
                cell.ImageView.Image = UIImage.FromBundle("preferences.png");
                break;
            case 2:
                cell.TextLabel.Text = "About";
                cell.ImageView.Image = UIImage.FromBundle("about.png");
                break;
            case 3:
                cell.TextLabel.Text = "Log Out";
                cell.ImageView.Image = UIImage.FromBundle("log_out.png");
                break;
        }

        return cell;
    }

    public override void RowSelected(UITableView tableView, Foundation.NSIndexPath indexPath)
    {
        tableView.DeselectRow(indexPath, true);
        switch (indexPath.Row)
        {
            case 0:
                // Navigate to Home.
                break;
            case 1:
                // Navigate to Preferences.
                break;
            case 2:
                // Navigate to About.
                break;
            case 3:
                // Navigate to Log Out...
                // HERE IS MY QUESTION: HOW CAN I PLACE THIS AS A
                // FOOTER TO THE FLYOUT DRAWER, IN THE VERY BOTTOM?

                // Here is the code thus far:

                cell.TranslatesAutoresizingMaskIntoConstraints = false;
                View.AddSubview(cell);

                cell.TopAnchor.ConstraintEqualTo(View.TopAnchor, 100).Active = true;
                cell.LeftAnchor.ConstraintEqualTo(View.LeftAnchor, 20).Active = true;
                cell.RightAnchor.ConstraintEqualTo(View.RightAnchor, -20).Active = true;
                cell.BottomAnchor.ConstraintEqualTo(View.BottomAnchor, -100).Active = true;

                // What should these numbers above be????

                break;
        }

        this.ShowViewController(vc, this);
    }
}

我的问题在最后一个“案例 3”部分:如何将最后一个选项作为页脚放在 Flyout Drawer 的最底部?

我的代码基于此 Nuget 包中的示例:

https://github.com/TheEightBot/Xamarin.SideMenu

谢谢。

///

更新:下面是我们正在努力完成的截图。谢谢。

最终更新:这是供参考的工作代码,Junior Jiang略有修改......

        UIImageView tableViewFooterImageView = new UIImageView(UIImage.FromBundle(“log_out.png”));

        var tableViewFooter = new UIView(new RectangleF(20, (float)UIScreen.MainScreen.Bounds.Height - 120, 375, 66));

        tableViewFooter.Add(tableViewFooterLabel);
        tableViewFooter.Add(tableViewFooterImageView);

        TableView.Add(tableViewFooter);

【问题讨论】:

    标签: ios xamarin xamarin.ios navigation-drawer footer


    【解决方案1】:

    不使用cell实现footer view,UITableView.TableFooterView Property可以做到。

    如下:

    UILabel label = new UILabel(new CoreGraphics.CGRect(0, 0, 200, 50));
    label.Text = "I am a footer view";
    label.TextAlignment = UITextAlignment.Center;
    label.BackgroundColor = UIColor.Cyan;
    this.TableView.TableFooterView = label;
    

    您可以在 TableFooterView 中自定义带有图像和标题的视图。

    【讨论】:

    • 非常感谢您的帮助。它非常接近我们的需要,但我的问题是:“我们可以将页脚一直移动到最底部吗?”我已附上屏幕截图作为主要问题的更新。
    • 更新:想通了。谢谢你的帮助。这是供参考的代码: UIImageView tableViewFooterImageView = new UIImageView(UIImage.FromBundle(“log_out.png”)); var tableViewFooter = new UIView(new RectangleF(20, (float)UIScreen.MainScreen.Bounds.Height - 120, 375, 66)); tableViewFooter.Add(tableViewFooterLabel); tableViewFooter.Add(tableViewFooterImageView); TableView.Add(tableViewFooter);
    • 谢谢您,先生。没有你是不可能做到的。 =)
    猜你喜欢
    • 2020-05-21
    • 1970-01-01
    • 2022-12-15
    • 1970-01-01
    • 2012-03-25
    • 1970-01-01
    • 2011-07-05
    • 1970-01-01
    • 2012-12-03
    相关资源
    最近更新 更多