自定义弹框视图

      很多时候 系统给的弹框视图并不能满足我们,由于产品的要求  不得不自定义弹框视图 在这里我写了一个自定义界面的弹框  展示界面如下 

如果需要 可以在这个界面随意添加你想要的效果  控制器代码如下

#import "ViewController.h"#import "LHAlertView.h"@interface ViewController ()@end

@implementation ViewController

- (void)viewDidLoad {

[super viewDidLoad];

UIButton *alertBtn = [UIButton buttonWithType:UIButtonTypeCustom];

alertBtn.frame = CGRectMake(50, 100, 100, 50);

[alertBtn setTitle:@"点击" forState:UIControlStateNormal];

alertBtn.backgroundColor = [UIColor grayColor];

[alertBtn addTarget:self action:@selector(alertBtnClick) forControlEvents:UIControlEventTouchUpInside];

[self.view addSubview:alertBtn];

}

//点击按钮 出现弹框

- (void)alertBtnClick{

LHAlertView *alertView = [[LHAlertView alloc] initWithFrame:[UIScreen mainScreen].bounds];

alertView.delegate = self;

NSArray *btnTitleArr = @[@"取消",@"确定"];

[alertView setContentStr:@"出现弹框出出现" type:10 btnNum:2 btntitleArr:btnTitleArr];

UIView *keywindow = [[UIApplication sharedApplication] keyWindow];

[keywindow addSubview: alertView];

}

#pragma mark - 代理事件

- (void)clickBottomBtnWithView:(LHAlertView *)alterView andClickBtn:(UIButton *)clickBtn{

if(clickBtn.tag == 100){

NSLog(@"点击了取消按钮");

}else{

NSLog(@"点击了确定按钮");

}

}

- (void)clickOtherPayMoneyWithView:(LHAlertView *)alterView andOtherPayMoneyBtn:(UIButton *)payMoney{

NSLog(@"点击了其他按钮");

}

@end

demo连接: https://git.oschina.net/huanni/myAlertView.git

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容