自定义UIAlertViewController选择视图

来源:互联网 发布:宏金赛鸽公棚扫猫数据 编辑:程序博客网 时间:2024/06/05 06:43

我的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:点击打开链接


原创粉丝点击