【问题标题】:How to make menus in a storyboard in xcode with cocoa and c#如何使用可可和c#在xcode中的故事板中制作菜单
【发布时间】:2021-08-25 03:04:04
【问题描述】:

我想制作许多菜单,例如防病毒软件。我想要它,所以当您单击左侧的众多按钮之一时,所有其他按钮将禁用,而该按钮将保持启用状态。它还将隐藏和取消隐藏故事板中的某些元素。我使用的是视觉工作室,但故事板使用的是 xcode。

这就是它的样子。然后在左边会显示我想要的元素。

【问题讨论】:

    标签: c# xcode macos visual-studio xamarin


    【解决方案1】:

    我们可以在代码中实现这一点,只需放置一系列按钮并在单击特定按钮时移除其他按钮。

    public override void ViewDidLoad()
            {
                base.ViewDidLoad();
    
                List<NSButton> array = new List<NSButton>();
                for (int i = 0; i < 10; i++)
                {
                    NSButton button = new NSButton();
                    button.Frame = new CGRect(5, 40 * i + 10, 100, 30);
                    button.Title = i.ToString();
                    button.Font = NSFont.SystemFontOfSize(20);
                    this.View.AddSubview(button);
                    array.Add(button);
    
                    button.Activated += (sender, e) =>
                    {
                        foreach(var b in array)
                        {
                            if(b != button)
                            {
                                b.RemoveFromSuperview();
                            }
                        }
                    };               
                }
            }
    

    【讨论】:

      猜你喜欢
      • 2012-01-08
      • 2012-07-30
      • 2014-03-06
      • 2015-07-24
      • 2022-12-29
      • 2012-05-09
      • 2016-11-09
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多