ごらくらいふ

プログラミングしたりゲームしたり

ActionSheetのラッパー「YJMActionSheet」を作りました!!

どうもyajamonです。

github.com

発端

iOS 8.3 にて、UIActionSheet が deprecated になりました。 代わりにUIAlertControllerの の使用を推奨されていますが、こちらは iOS 8.0 からしか利用できません。

まだ iOS 8.0 未満を切り捨てるのは早いということで、UIActionSheetと共存する必要がありました。

ラッパーを作りました

そこで、UIAlertController を UIActionSheet っぽく扱うように寄せるかたちで、UIAlertController、UIActionSheet のラッパーを作成しました!

このラッパーは、iOSのバージョンをもとに、内部でUIAlertControllerとUIActionSheetを使い分けます。

使い方

READMEにある使い方を転載します。

// bound method
- (IBAction)openActionSheet:(id)sender {
    // create title and action
    YJMAction *cancel = [[YJMAction alloc] initWithTitle:@"cancel" action:^(){
        // write processing when the user taps cancel
    }];
    YJMAction *other = [[YJMAction alloc] initWithTitle:@"other" action:^(){
        // write processing when the user taps other
    }];

    // create ActionSheet instance
    self.actionSheet = [[YJMActionSheet alloc] initWithTitle:@"Sheet title"
                                                cancelAction:cancel
                                           destructiveAction:nil
                                                 otherAction:other];

    // show ActionSheet
    [self.actionSheet showInViewController:self];
}

いじょう!