如何在 Xamarin.Ios 中将页脚添加到 Flyout Drawer?
How to add footer to Flyout Drawer in Xamarin.Ios?
我正在尝试为原生 Xamarin.ios 添加页脚到 Flyout Drawer。
要求类似于这两个 Android 问题,除了我需要为 iOS native:
完成
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);
}
}
我的问题在最后 "Case 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);
不用cell实现页脚视图,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 中自定义带有图像和标题的视图。
我正在尝试为原生 Xamarin.ios 添加页脚到 Flyout Drawer。
要求类似于这两个 Android 问题,除了我需要为 iOS native:
完成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);
}
}
我的问题在最后 "Case 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);
不用cell实现页脚视图,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 中自定义带有图像和标题的视图。