//
// LXLAlterView.h
// MoreIn
//
// Created by 李学亮 on 2017/5/15.
// Copyright © 2017年 person. All rights reserved.
//
#import <UIKit/UIKit.h>
typedef void(^cancelBlock)(UIAlertAction *action);
typedef void(^sureBlock)(UIAlertAction *action);
@interface LXLAlterView : NSObject
/**
*
* @param title 标题
* @param content 内容
* @param cancel 取消按钮内容
* @param sure 确定按钮内容
* @param cancelBlock 取消按钮点击事件
* @param sureBlock 确定按钮点击事件
*
*/
+ (UIAlertController *)alterViewWithTitle:(NSString *)title
content:(NSString *)content
cancel:(NSString *)cancel
sure:(NSString *)sure
cancelBtClcik:(cancelBlock)cancelBlock
sureBtClcik:(sureBlock)sureBlock;
@end
——————————————————————————————————————————————————
//
// LXLAlterView.m
// MoreIn
//
// Created by 李学亮 on 2017/5/15.
// Copyright © 2017年 person. All rights reserved.
//
#import "LXLAlterView.h"
@implementation LXLAlterView
#pragma mark----实现类方法
+ (UIAlertController *)alterViewWithTitle:(NSString *)title
content:(NSString *)content
cancel:(NSString *)cancel
sure:(NSString *)sure
cancelBtClcik:(cancelBlock)cancelBlock
sureBtClcik:(sureBlock)sureBlock;
{
UIAlertController * aletVC = [UIAlertController alertControllerWithTitle:title message:content preferredStyle:(UIAlertControllerStyleAlert)];
UIAlertAction *sureAction = [UIAlertAction actionWithTitle:sure style:(UIAlertActionStyleDefault) handler:^(UIAlertAction * _Nonnull action) {
sureBlock(action);
}];
[aletVC addAction:sureAction];
if (cancel != nil) {
UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:cancel style:(UIAlertActionStyleCancel) handler:^(UIAlertAction * _Nonnull action) {
cancelBlock(action);
}];
[aletVC addAction:cancelAction];
}
return aletVC;
}
@end
调用界面
UIAlertController * altVC = [LXLAlterView alterViewWithTitle:@"title" content:metadataObject.stringValue cancel:@"取消" sure:@"确定" cancelBtClcik:^(UIAlertAction *action) {
} sureBtClcik:^(UIAlertAction *action) {
}];
[self presentViewController:altVC animated:YES completion:nil];