在Monotouch的Evolve FlyoutNavigationController中为菜单项添加图标

时间:2014-09-08 22:53:53

标签: ios uinavigationcontroller xamarin.ios

我的Evolve Flyout导航控制器在我的iOS应用程序上工作,但我不确定如何在此代码中添加图标。我想在每个菜单项的左侧显示一个图标,并且该菜单项是唯一的。这是我的代码:

// Subclass the component to keep the configuration in one place
using FlyoutNavigation;

namespace Mobile.iOS7
{
    public class EvolveFlyoutNavigationController : FlyoutNavigationController
    {
    string[] MenuTasks = {
        "Menu Item One",
        "Menu Item Two",
        "Menu Item Three",
        "Menu Item Four",
    };

    UINavigationController notImplementedVC; 

    public EvolveFlyoutNavigationController () : base ()
    {
        // Create the navigation menu
        var menuSection = new Section ();
        foreach(var page in MenuTasks)
            menuSection.Add(new StyledStringElement (page) { BackgroundColor = MyColors.DarkGray, TextColor = UIColor.White, Font = UIFont.FromName("Lato-Black", 16f) });

        NavigationRoot = new RootElement ("Menu") {
            menuSection
        };

        List <UINavigationController> vcList = new List<UINavigationController> ();

        var mainSB = UIStoryboard.FromName ("MainStoryboard", null);
        vcList.Add(new UINavigationController (mainSB.InstantiateViewController ("DashboardViewController") as DashboardViewController));
        vcList.Add(new UINavigationController (mainSB.InstantiateViewController ("LocatorTabController") as LocatorTabController));


        ViewControllers = vcList.ToArray ();

        NavigationTableView.BackgroundView = new UIImageView (new UIImage ("bg-nav.png"));
        NavigationTableView.SeparatorColor = UIColor.LightGray;
    }
 }
}

非常感谢任何帮助!

1 个答案:

答案 0 :(得分:0)

使用StyledStringElement正在使用MonoTouch.Dialog绘制菜单。此元素支持ImageUri属性,可用于指定要显示的图像:

menuSection.Add(new StyledStringElement (page) { 
  BackgroundColor = MyColors.DarkGray, 
  TextColor = UIColor.White, 
  Font = UIFont.FromName("Lato-Black", 16f),
  ImageUri = new Uri(__path_to_your_image__)
});