自定义UIAlertViewController选择视图

我的GitHub:点击打开链接

进入我的git,下载项目

在自己的项目中导入头文件

#import "AlertAction.h"

#import "AlertView.h"

实现一下代码即可:

{

    //选择图片显示在第几行

    NSInteger _actionImgShowRow;

}

@property (weak,nonatomic) IBOutletUILabel *textLabel;

@end

@implementation ViewController


- (void)viewDidLoad {

    [superviewDidLoad];

    _actionImgShowRow =0;

}

//图片固定不变

- (IBAction)AlertClick:(id)sender {

    AlertView *alertView = [AlertViewpopoverView];

    alertView.backgroundColor=[UIColorclearColor];

    alertView.showShade =YES; //显示阴影背景

    [alertView showWithActions:[selfQQActions]];

}

//显示选择行数

- (IBAction)selectAlertClick:(id)sender {

    AlertView *alertView = [AlertViewpopoverView];

    alertView.backgroundColor=[UIColorclearColor];

    alertView.showShade =YES; //显示阴影背景

    [alertView showWithActions:[selfselectActions]];


}

//图片不会被隐藏

- (NSMutableArray<AlertAction *> *)QQActions {

    // 发起多人聊天 action

    AlertAction *multichatAction = [AlertActionactionWithImage:[UIImageimageNamed:@"right_menu_multichat"]title:@"发起多人聊天"handler:^(AlertAction *action) {

        _textLabel.text =@"发起多人聊天";

    }];

    // 加好友 action

    AlertAction *addFriAction = [AlertActionactionWithImage:[UIImageimageNamed:@"right_menu_addFri"]title:@"加好友"handler:^(AlertAction *action) {

        _textLabel.text =@"加好友";

    }];

    // 扫一扫 action

    AlertAction *QRAction = [AlertActionactionWithImage:[UIImageimageNamed:@"right_menu_QR"]title:@"扫一扫"handler:^(AlertAction *action) {

        _textLabel.text =@"扫一扫";

    }];

    // 面对面快传 action

    AlertAction *facetofaceAction = [AlertActionactionWithImage:[UIImageimageNamed:@"right_menu_facetoface"]title:@"面对面快传"handler:^(AlertAction *action) {

        _textLabel.text =@"面对面快传";

    }];

    // 付款 action

    AlertAction *payMoneyAction = [AlertActionactionWithImage:[UIImageimageNamed:@"right_menu_payMoney"]title:@"付款"handler:^(AlertAction *action) {

        _textLabel.text =@"付款";

    }];

    // 取消

    AlertAction *cancelAction = [AlertActionactionWithTitle:@"取消"handler:^(AlertAction *action) {

        _textLabel.text =@"取消";

    }];

    NSArray *section1 =@[multichatAction, addFriAction, QRAction, facetofaceAction, payMoneyAction];

    NSArray *section2 =@[cancelAction];

    NSMutableArray *actionArr=[NSMutableArrayarrayWithObjects:section1, section2,nil];

    return actionArr;

}

//图片默认隐藏,选择后对应行数显示

- (NSMutableArray<AlertAction *> *)selectActions {

    // 全部支付 action

    AlertAction *allPayAction = [AlertActionactionWithImage:[UIImageimageNamed:@"selcetShape"]title:@"全部支付"handler:^(AlertAction *action) {

        _textLabel.text =@"全部支付";

        _actionImgShowRow =0;

    }];

    // 快捷支付 action

    AlertAction *fastAction = [AlertActionactionWithImage:[UIImageimageNamed:@"selcetShape"]title:@"快捷支付"handler:^(AlertAction *action) {

        _textLabel.text =@"快捷支付";

        _actionImgShowRow =1;

    }];

    // 银行划账 action

    AlertAction *bankAction = [AlertActionactionWithImage:[UIImageimageNamed:@"selcetShape"]title:@"银行划账"handler:^(AlertAction *action) {

        _textLabel.text =@"银行划账";

        _actionImgShowRow =2;

    }];

    // 微信支付 action

    AlertAction *weixinAction = [AlertActionactionWithImage:[UIImageimageNamed:@"selcetShape"]title:@"微信支付"handler:^(AlertAction *action) {

        _textLabel.text =@"微信支付";

        _actionImgShowRow =3;

    }];

    // 支付宝支付 action

    AlertAction *zhifubaoAction = [AlertActionactionWithImage:[UIImageimageNamed:@"selcetShape"]title:@"支付宝支付"handler:^(AlertAction *action) {

        _textLabel.text =@"支付宝支付";

        _actionImgShowRow =4;

    }];

    // 取消

    AlertAction *cancelAction = [AlertActionactionWithTitle:@"取消"handler:^(AlertAction *action) {

        _textLabel.text =@"取消";

    }];

    

    NSArray *section1 =@[allPayAction, fastAction, bankAction, weixinAction, zhifubaoAction];

    NSArray *section2 =@[cancelAction];

    AlertAction *alert=[[AlertActionalloc]init];

    alert.selectRow =_actionImgShowRow;

    NSMutableArray *actionArr=[NSMutableArrayarrayWithObjects:section1, section2, alert,nil];

    return actionArr;

}


我的GitHub:点击打开链接


  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值