Created
July 8, 2012 17:25
-
-
Save hfm/3071913 to your computer and use it in GitHub Desktop.
UIActionSheetのキャンセルボタンを最下部に設定する(ユニバーサル仕様)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// UIActionSheetクラスを作成する | |
// cancelButtonとdestructiveButtonはどちらかをnilにしておく | |
UIActionSheet *sheet; | |
sheet = [[UIActionSheet alloc] initWithTitle:@"写真選択" | |
delegate:self | |
cancelButtonTitle:@"キャンセル" | |
destructiveButtonTitle:nil | |
otherButtonTitles:@"カメラ", @"ライブラリ", nil]; | |
[sheet showInView:self.view]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// UIActionSheetクラスを作成する | |
// cancelButtonとdestructiveButtonはnilにしておく | |
UIActionSheet *sheet; | |
sheet = [[UIActionSheet alloc] initWithTitle:@"写真選択" | |
delegate:self | |
cancelButtonTitle:nil | |
destructiveButtonTitle:nil | |
otherButtonTitles:@"カメラ", @"ライブラリ", nil]; | |
// キャンセルボタンをアクションシートの最下に設定する | |
[sheet addButtonWithTitle:@"キャンセル"]; | |
[sheet setCancelButtonIndex:[sheet numberOfButtons] - 1]; | |
[sheet showInView:self.view]; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
初期化オーバーライドに
cancelButtonTitle:@"キャンセル"
と設定しておけばiPhoneではキャンセルボタンが表示されるが、iPadではcancelButtonは表示されない。iPadにおけるキャンセルはアクションシートの領域外をタッチすることである。
そこで、上記のように
addButtonWithTitle:
メソッドでボタンを追加し、setCancelButtonIndex:
メソッドで追加したボタンにキャンセルボタンの役割を与えることで、iPhone/iPadで同じように表示できる。