gpt4 book ai didi

iphone - 带有隐藏菜单的按钮 iPhone

转载 作者:行者123 更新时间:2023-11-29 04:52:53 26 4
gpt4 key购买 nike

我需要实现一个按钮,该按钮将显示在 UIView 或 MKMapView 上应用程序的右上角。单击该按钮后,应该会出现一个组合,用户可以选择类别。

我怎样才能实现这一目标?

最佳答案

您必须创建一个 UIButton 并将其添加为 UIView 的 subview (例如,如果您的 View 链接到 UIViewController,则在 viewDidLoad 方法中)。

UIButton *showButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
showButton.frame = CGRectMake(500, 20, 150, 44); // hardcoded frame, not quite elegant but works if you know the dimension of your superview
[showButton setTitle:@"Show Categories" forState:UIControlStateNormal];
// add target and actions
[showButton addTarget:self action:@selector(buttonClicked:) forControlEvents:UIControlEventTouchUpInside];
// add to a superview, your parent view
[superView addSubview:showButton];

然后添加一个名为“buttonClicked:”的方法,该方法采用 id 参数(通常是发送者,在本例中为 showButton)。

-(void)buttonClicked:(id)sender
{
// visualize categories
}

要可视化类别,您可以采用两种不同的方式:

  1. 在 UIPopoverController 中呈现 UITableViewController(仅适用于 iPad 设备)
  2. 显示一个呈现 UITableViewController 的模态 Controller (iPad 和 iPhone 设备)。

UITableViewController 允许您拥有一个类别列表,然后选择其中一个。

附言检查XCode中的代码,因为我是手写的(没有XCode)

关于iphone - 带有隐藏菜单的按钮 iPhone,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8520886/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com