c# - 如何使用可可和c#在xcode中的故事板中制作菜单
问题描述
我想做很多像杀毒软件一样的菜单。我想要它,所以当您单击左侧的众多按钮之一时,所有其他按钮将禁用,而该按钮将保持启用状态。它还将隐藏和取消隐藏故事板中的某些元素。我使用的是视觉工作室,但故事板使用的是 xcode。
这就是它的样子。然后在左边它将显示我想要的元素。
解决方案
我们可以在代码中实现这一点,只需放置一系列按钮并在单击特定按钮时移除其他按钮。
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();
}
}
};
}
}
推荐阅读
- c# - 当 C# 从 C++ 调用函数时,如何编组包含结构作为输入/输出参数的映射?
- c# - 如何连接和断开代理?
- javascript - 如何使用预输入?
- php - SQL LIKE 字面上没有显示任何结果(根本)
- c++ - 我有一个嵌套数组,它由另一个数组中的元素组成 2 。之后,我想显示每个元素的属性
- excel - 有没有办法旋转 OLEobjects?
- django - 博客文章不显示图像、粗体文本或其他属性,仅显示原始代码... Django/Ckeditor
- javascript - 如何将jsx元素存储到javascript变量
- rust - 如何固定库的间接依赖项?
- angular - 如何在不刷新的情况下更新角度页面?