![](/img/trans.png)
[英]Adding UIPickerView to UIActionSheet (buttons at the bottom)
[英]UIActionSheet with UIPickerView and Done, Next, Previous buttons
我正在尝试实现一个包含选择器视图和分段控制栏的操作表,其中包含上一个按钮、下一个按钮和完成按钮,如下图所示http://imgur.com/8wVMy 。 我目前能够使它看起来像这样http://imgur.com/AXn6H 。 我想知道是否有人可以帮助我将选择器视图放在底部并让它看起来更好一点。 谢谢你的帮助。
除非您的目标是非常旧的 iOS 版本(即早于 3.2 的版本),否则最好的方法是采用完全不同的方法。
从 3.2 开始,任何 UIResponder(包括所有 UIView)都可以从其inputView
属性返回 UIView 以在视图成为第一响应者时显示该视图而不是键盘。 这甚至适用于通常不会成为第一响应者或根本不显示键盘的视图。 这很简单:
canBecomeFirstResponder
返回 YES。inputView
返回弹出视图的实例。文档中提供了更多详细信息。
另外,顺便说一句,如果您使用的是 iPad,您可能应该使用 UIPopoverController 来显示 UIPickerView 而不是这些方法中的任何一种。 如果您打算在应用商店中获取您的应用,Apple 实际上可能会要求这样做。
下一个和上一个按钮实际上是在工具栏中将您的图像显示给分段控制器。 要得到它你必须定义segmentedController和UIToolbar。 H. 接下来添加 DataSource 和 UIPickerView 然后在 viewDidLoad 创建对象并定义它们的属性。 例如:
if (keyboardToolbar == nil) {
keyboardToolbar = [[UIToolbar alloc] initWithFrame:CGRectMake(0, 0, self.view.bounds.size.width, 44)];
[keyboardToolbar setBarStyle:UIBarStyleBlackTranslucent];
segControl = [[UISegmentedControl alloc] initWithItems:[NSArray arrayWithObjects:@"Anterior", @"Siguiente", nil]];
[segControl setSegmentedControlStyle:UISegmentedControlStyleBar];
[segControl setTintColor:[UIColor blackColor]];
segControl.frame = CGRectMake(5, 7, 150, 33);
segControl.momentary = YES;
[segControl addTarget:self action:@selector(segSelected:) forControlEvents:UIControlEventValueChanged];
UIBarButtonItem *extraSpace = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil];
UIBarButtonItem *aceptar = [[UIBarButtonItem alloc] initWithTitle:@"Hecho" style:UIBarButtonItemStyleDone target:self action:@selector(cerrarTeclado:)];
//aceptar.width = 70.0f;
[keyboardToolbar setItems:[[NSArray alloc] initWithObjects: extraSpace, aceptar, nil]];
[keyboardToolbar addSubview:segControl];
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.