iOS开发——ActionSheet的使用与弹出选择对话框

     在我们的iOS开发中,常会见到如下界面的需求:



也就是点击按钮,出现选择提示框,我们今天使用两种方式(ActionSheet和AlertController)来实现该功能。示例代码上传至: https://github.com/chenyufeng1991/iOS-ActionSheet   。

【使用ActionSheet实现】

(1)实现代码如下:

#import "ViewController.h"

@interface ViewController ()<UIActionSheetDelegate>

@end

@implementation ViewController

- (void)viewDidLoad {
  [super viewDidLoad];

}

#pragma mark - 按钮点击事件
- (IBAction)actionSheetButtonPressed:(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
   UIActionSheetStyleDefaul
  • 5
    点赞
  • 14
    收藏
    觉得还不错? 一键收藏
  • 6
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 6
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值