创buildUIActionSheet
我想创build这种菜单,当然还有其他菜单button。 有没有代表它的默认视图控制器,或者我必须得到图像,并由我自己创build。
您需要使用UIActionSheet
。
首先,您需要将UIActionSheetDelegate
添加到ViewController.h文件中。
然后你可以参考一个操作表:
UIActionSheet *popup = [[UIActionSheet alloc] initWithTitle:@"Select Sharing option:" delegate:self cancelButtonTitle:@"Cancel" destructiveButtonTitle:nil otherButtonTitles: @"Share on Facebook", @"Share on Twitter", @"Share via E-mail", @"Save to Camera Roll", @"Rate this App", nil]; popup.tag = 1; [popup showInView:self.view];
那么你必须处理每个电话。
- (void)actionSheet:(UIActionSheet *)popup clickedButtonAtIndex:(NSInteger)buttonIndex { switch (popup.tag) { case 1: { switch (buttonIndex) { case 0: [self FBShare]; break; case 1: [self TwitterShare]; break; case 2: [self emailContent]; break; case 3: [self saveContent]; break; case 4: [self rateAppYes]; break; default: break; } break; } default: break; } }
对于iOS 8.x已经被弃用了https://developer.apple.com/documentation/uikit/uialertcontroller#//apple_ref/occ/cl/UIAlertController
看一下UIActionSheet文档。
NSString *actionSheetTitle = @"Action Sheet Demo"; //Action Sheet Title NSString *destructiveTitle = @"Destructive Button"; //Action Sheet Button Titles NSString *other1 = @"Other Button 1"; NSString *other2 = @"Other Button 2"; NSString *other3 = @"Other Button 3"; NSString *cancelTitle = @"Cancel Button"; UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:actionSheetTitle delegate:self cancelButtonTitle:cancelTitle destructiveButtonTitle:destructiveTitle otherButtonTitles:other1, other2, other3, nil]; [actionSheet showInView:self.view];
它被称为UIActionSheet:你创build一个这样的:
NSString *actionSheetTitle = @"Action Sheet Demo"; //Action Sheet Title NSString *destructiveTitle = @"Destructive Button"; //Action Sheet Button Titles NSString *other1 = @"Other Button 1"; NSString *other2 = @"Other Button 2"; NSString *other3 = @"Other Button 3"; NSString *cancelTitle = @"Cancel Button"; UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:actionSheetTitle delegate:self cancelButtonTitle:cancelTitle destructiveButtonTitle:destructiveTitle otherButtonTitles:other1, other2, other3, nil]; [actionSheet showInView:self.view];
实现UISctionSheetDelegate以响应button操作。
看看这个教程更多的信息: http : //mobile.tutsplus.com/tutorials/iphone/uiactionsheet_uiactionsheetdelegate (代码是从这个教程)