iOS开发-UIActionSheet和UIAlertController

来源:互联网 发布:弹簧刀 知乎 编辑:程序博客网 时间:2024/06/05 08:57

ActionSheet

- (void)buttonPressed:(id)sender{    /**     UIActionSheet已经在8.3后被弃用了,如果想要去掉警告信息,可以把项目的Deployment Target设置为8.3以下,就可以去掉警告了。     */    /**     Title:如果不想要title,可以设置为nil;     注意需要实现UIActionSheetDelegate;     destructiveButtonTitle:设置的按钮文字是红色的;     otherButtonTitles:按照按钮顺序;     */    UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:@"这是标题" delegate:self cancelButtonTitle:@"取消" destructiveButtonTitle:@"确定" otherButtonTitles:nil];    /**     *     UIActionSheetStyleAutomatic     UIActionSheetStyleDefault     UIActionSheetStyleBlackTranslucent     UIActionSheetStyleBlackOpaque     */    //这里的actionSheetStyle也可以不设置;    actionSheet.actionSheetStyle = UIActionSheetStyleAutomatic;    [actionSheet showInView:self.view];     }

AlertController

- (void)buttonPressed1:(id)sender{    NSLog(@"dianji");    // 初始化提示框    UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"提示" message:@"Message" preferredStyle:UIAlertControllerStyleActionSheet];    [alert addAction:[UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {        NSLog(@"点击确定");    }]];    [alert addAction:[UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {        NSLog(@"点击取消");    }]];    [self presentViewController:alert animated:true completion:nil];}
4 0
原创粉丝点击