自定義彈框視圖

? ? ? 很多時候 系統(tǒng)給的彈框視圖并不能滿足我們,由于產品的要求? 不得不自定義彈框視圖 在這里我寫了一個自定義界面的彈框? 展示界面如下?

如果需要 可以在這個界面隨意添加你想要的效果 ?控制器代碼如下

#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];

}

//點擊按鈕 出現(xiàn)彈框

- (void)alertBtnClick{

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

alertView.delegate = self;

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

[alertView setContentStr:@"出現(xiàn)彈框出出現(xiàn)" 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

最后編輯于
?著作權歸作者所有,轉載或內容合作請聯(lián)系作者
【社區(qū)內容提示】社區(qū)部分內容疑似由AI輔助生成,瀏覽時請結合常識與多方信息審慎甄別。
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發(fā)布,文章內容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務。

相關閱讀更多精彩內容

友情鏈接更多精彩內容