[iOS][Objective-C] UIAlertViewでタイトルを非表示にする

タイトル画像のようにiOSでボタンのみの縦並びの選択ダイアログを表示する方法です。
結論としては、UIAlertControllerのtitleとmessageにnilを設定すれば良いです。

サンプルソース

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
// UIAlertControllerを作成する際にtitle, messageにnilを設定するのがミソ
UIAlertController *alertController = [UIAlertController alertControllerWithTitle:nil
                                                                         message:nil
                                                                  preferredStyle:UIAlertControllerStyleAlert];
// ボタンなどはお好みで増やせます
UIAlertAction *firstButtonAction = [UIAlertAction actionWithTitle:@"First"
                                                            style:UIAlertActionStyleDefault
                                                          handler:^(UIAlertAction *action){
 
                                                          }];
UIAlertAction *secondButtonAction = [UIAlertAction actionWithTitle:@"Second"
                                                             style:UIAlertActionStyleDefault
                                                           handler:^(UIAlertAction *action){
 
                                                           }];
UIAlertAction *cancelButtonAction = [UIAlertAction actionWithTitle:@"Cancel"
                                                             style:UIAlertActionStyleCancel
                                                           handler:^(UIAlertAction *action){
 
                                                           }];
// UIAlertControllerにActionを追加して
[alertController addAction:firstButtonAction];
[alertController addAction:secondButtonAction];
[alertController addAction:cancelButtonAction];
 
// ViewControllerのメソッドで表示させます
[self presentModalViewController:alertController animated:YES];

空白文字「@""」を設定しても期待したようにならないのでご注意ください。

しかし、iOSアプリをしばらく書いていなかったので、忘れている事が多いです。
趣味の時間にでも少しは触っておかないと、いざという時に作業スピードが落ちてしまいます。

でも最近はDeep Learningも気になっていて、時間が足りないです。

0 件のコメント :

コメントを投稿