学无止境上海恩美路演牛叉的demo

自定义弹框视图

2016-12-14  本文已影响82人  薰衣草儿

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

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

#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

上一篇 下一篇

猜你喜欢

热点阅读