本文代码源于自己的项目,亲测可行,简单易上手。
我们知道,从iOS8后,已经使用UIAlertController来取代UIAlertView和UIAlertSheet。
弹出菜单的方法,实现如下:
-(void)creatActionSheet {
/*
先创建UIAlertController,preferredStyle:选择UIAlertControllerStyleActionSheet,这个就是相当于创建8.0版本之前的UIActionSheet;
typedef NS_ENUM(NSInteger, UIAlertControllerStyle) {
UIAlertControllerStyleActionSheet = 0,
UIAlertControllerStyleAlert
} NS_ENUM_AVAILABLE_IOS(8_0);
*/
UIAlertController *actionSheet = [UIAlertController alertControllerWithTitle:@"选择对象" message:nil preferredStyle:UIAlertControllerStyleActionSheet];
/*
typedef NS_ENUM(NSInteger, UIAlertActionStyle) {
UIAlertActionStyleDefault = 0,
UIAlertActionStyleCancel, 取消按钮
UIAlertActionStyleDestructive 破坏性按钮,比如:“删除”,字体颜色是红色的
} NS_ENUM_AVAILABLE_IOS(8_0);