[英]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.