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

标签 iphone objective-c ios uibutton

我需要实现一个按钮,该按钮将显示在 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/

相关文章:

iphone - 是否有适用于 iPhone 的原生 YAML 库?

iphone - 从子类应用程序委托(delegate)调用应用程序委托(delegate)方法

ios - 如何将 SQLite 文件从 Documents 目录保存回 Objective-C 中的主包?

iphone - 如何在键盘处于事件状态时隐藏 iPhone 上的文本字段光标

objective-c - +[GKPlayer loadPlayersForIdentifiers :completionHandler:] 中返回的数组顺序

ios - 我怎样才能防止用户点击按钮两次,这样当用户关闭应用程序并打开他仍然无法点击

iphone - 使用 Objective C(音频队列服务)从 FFMPeg 获取准确时间

iphone - 使用clipToMask时图像旋转90度

iphone - Cocos2d中的倒数计时器?

iphone - UILabel UILongPressGestureRecognizer 不工作?