1

I'm trying to add a footer to the Flyout Drawer for Native Xamarin.ios.

The requirement is similar to these two Android questions, except that I need it done for iOS native:

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

and

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

My question is in the last "Case 3" part: How can I place the last option as a footer to the Flyout Drawer, in the very bottom?

I'm basing my code off the sample in this Nuget Package:

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

Thank you.

///

UPDATE: Below is a screenshot of what we are trying to accomplish. Thank you.

enter image description here

FINAL UPDATE: Here is the working code for reference, with slight modification from 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);
MrProgrammer
  • 589
  • 1
  • 7
  • 17

1 Answers1

1

Not using cell to realize footer view , UITableView.TableFooterView Property can do that.

As follow:

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;

enter image description here

You can custom a View with image & title in TableFooterView .

Junior Jiang
  • 12,430
  • 1
  • 10
  • 30
  • Thank you very much for your help. It is very close to what we need, but my question is this: "Can we move the footer all the way down to the very bottom?" I have attached the screenshot as an update to the main question. – MrProgrammer Aug 07 '19 at 17:39
  • Update: Figured it out. Thanks for your help. Here is the code for reference: 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); – MrProgrammer Aug 07 '19 at 23:08
  • Thank you, sir. Couldn't have done it without you. =) – MrProgrammer Aug 08 '19 at 16:59