MMPopupView(自定义UIAlertView、UIActionSheet、UIDatePicker)

自定义的UIAlertView、UIActionSheet、UIDatePicker,挺好的,是github上的东西。地址是:https://github.com/adad184/MMPopupView
首先是导入Masonry的库(个人喜好而已,可以不用Masonry),接着导入头文件#import “MMPopupItem.h”、#import “MMAlertView.h”、#import “MMSheetView.h”、#import “MMPinView.h”、#import “MMDateView.h”、#import “MMPopupWindow.h”。然后….然后就是上代码了。

@interface ViewController ()

@property (nonatomic, strong) UIButton *btnAlert;
@property (nonatomic, strong) UIButton *btnConfirm;
@property (nonatomic, strong) UIButton *btnInput;
@property (nonatomic, strong) UIButton *btnSheet;
@property (nonatomic, strong) UIButton *btnPin;
@property (nonatomic, strong) UIButton *btnDate;

@end

@implementation ViewController

- (void)viewDidLoad
{
    [super viewDidLoad];

    self.view.backgroundColor = [UIColor whiteColor];

    self.btnAlert   = [UIButton buttonWithType:UIButtonTypeCustom];
    self.btnConfirm = [UIButton buttonWithType:UIButtonTypeCustom];
    self.btnInput   = [UIButton buttonWithType:UIButtonTypeCustom];
    self.btnSheet   = [UIButton buttonWithType:UIButtonTypeCustom];
    self.btnPin     = [UIButton buttonWithType:UIButtonTypeCustom];
    self.btnDate    = [UIButton buttonWithType:UIButtonTypeCustom];

    NSArray *arrayButton = @[self.btnAlert, self.btnConfirm, self.btnInput, self.btnSheet, self.btnPin, self.btnDate];
    NSArray *arrayTitle  = @[@"Alert - Default", @"Alert - Confirm", @"Alert - Input", @"Sheet - Default", @"Custom - PinView", @"Custom - DateView"];

    for ( int i = 0 ; i < arrayButton.count; ++i ){
        UIButton *btn = arrayButton[i];
        [self.view addSubview:btn];
        [btn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerX.equalTo(self.view);
            make.top.equalTo(self.view.mas_top).offset(100 + i*60);
            make.size.mas_equalTo(CGSizeMake(180, 40));
        }];

        [btn setTitle:arrayTitle[i] forState:UIControlStateNormal];
        [btn setBackgroundColor:[UIColor blackColor]];
        [btn addTarget:self action:@selector(actionButton:) forControlEvents:UIControlEventTouchUpInside];
        btn.tag = i;
    }

    [[MMPopupWindow sharedWindow] cacheWindow];
    [MMPopupWindow sharedWindow].touchWildToHide = YES;

    MMAlertViewConfig *alertConfig = [MMAlertViewConfig globalConfig];
    MMSheetViewConfig *sheetConfig = [MMSheetViewConfig globalConfig];

    alertConfig.defaultTextOK = @"OK";
    alertConfig.defaultTextCancel = @"Cancel";
    alertConfig.defaultTextConfirm = @"Confirm";

    sheetConfig.defaultTextCancel = @"Cancel";
}

- (void)actionButton:(UIButton*)btn
{
    MMPopupItemHandler block = ^(NSInteger index){
        NSLog(@"clickd %@ button",@(index));
    };

    MMPopupBlock completeBlock = ^(MMPopupView *popupView){
        NSLog(@"animation complete");
    };

    switch ( btn.tag) {
        case 0:
        {
            NSArray *items =
            @[MMItemMake(@"Done", MMItemTypeNormal, block),
              MMItemMake(@"Save", MMItemTypeHighlight, block),
              MMItemMake(@"Cancel", MMItemTypeNormal, block)];

            MMAlertView *alertView = [[MMAlertView alloc] initWithTitle:@"AlertView"
                                         detail:@"each button take one row if there are more than 2 items"
                                          items:items];
            alertView.attachedView = self.view;

            [alertView show];

            break;
        }
        case 1:
        {
            [[[MMAlertView alloc] initWithConfirmTitle:@"AlertView" detail:@"Confirm Dialog"] showWithBlock:completeBlock];
            break;
        }
        case 2:
        {
            [[[MMAlertView alloc] initWithInputTitle:@"AlertView" detail:@"Input Dialog" placeholder:@"Your placeholder" handler:^(NSString *text) {
                NSLog(@"input:%@",text);
            }] showWithBlock:completeBlock];
            break;
        }
        case 3:
        {
            NSArray *items =
            @[MMItemMake(@"Normal", MMItemTypeNormal, block),
              MMItemMake(@"Highlight", MMItemTypeHighlight, block),
              MMItemMake(@"Disabled", MMItemTypeDisabled, block)];

            [[[MMSheetView alloc] initWithTitle:@"SheetView"
                                          items:items] showWithBlock:completeBlock];
            break;
        }
        case 4:
        {
            MMPinView *pinView = [MMPinView new];

            [pinView showWithBlock:completeBlock];

            break;
        }
        case 5:
        {
            MMDateView *dateView = [MMDateView new];

            [dateView showWithBlock:completeBlock];

            break;
        }

        default:
            break;
    }
}

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
}

@end
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值