前言
因為工程需要配套的提示框,蘋果自帶的UIAlertViewController滿足不了需求就自己封裝了一個。不但有UIAlertViewController所有的功能,還有自定義背景,顏色,內(nèi)容等。
演示

演示demo.gif
主要代碼
初始化一個普通彈框
RAlertViewController *alertVC = [RAlertViewController alertControllerWithTitle:@"提示" message:@"點擊了普通彈框-運用類方法初始化"];
[alertVC addAtionButtonTitle:@"確定" Handle:^(UIButton *sender) {
NSLog(@"點擊了確定");
}];
[alertVC addAtionButtonTitle:@"取消" Handle:^(UIButton *sender) {
NSLog(@"點擊了取消");
}];
[self presentViewController:alertVC animated:YES completion:nil];
初始化三個按鈕的
RAlertViewController *alertVC = [[RAlertViewController alloc] init];
alertVC.titleString = @"提示";
alertVC.messageString = @"點擊了普通彈框-運用init方法初始化";
[alertVC addAtionButtonTitle:@"確定" Handle:^(UIButton *sender) {
NSLog(@"點擊了確定");
}];
[alertVC addAtionButtonTitle:@"取消" Handle:^(UIButton *sender) {
NSLog(@"點擊了取消");
}];
[alertVC addAtionButtonTitle:@"╮(╯_╰)╭" Handle:^(UIButton *sender) {
NSLog(@"點擊了╮(╯_╰)╭");
}];
[self presentViewController:alertVC animated:YES completion:nil];
初始化帶圖彈框
RAlertViewController *alertVC = [[RAlertViewController alloc] init];
// alertVC.titleString = @"提示";
alertVC.titleImage = [UIImage imageNamed:@"takephotobutton"];
alertVC.messageString = @"點擊了帶圖片彈框-運用init方法初始化";
[alertVC addAtionButtonTitle:@"取消" Handle:^(UIButton *sender) {
NSLog(@"點擊了取消");
}];
[self presentViewController:alertVC animated:YES completion:nil];
文字自適應(yīng)
RAlertViewController *alertVC = [[RAlertViewController alloc] init];
alertVC.titleString = @"提示";
alertVC.titleImage = [UIImage imageNamed:@"heart"];
alertVC.messageString = @"當(dāng)你看著這么多的星星時,你會有什么感覺?”小國王問。“我感覺自己很渺小,也很不重要?!蔽艺f,“我感覺自己變得和你一樣小——甚至更小。我感覺這個世界是如此之大,而我不過是滄海一粟?!薄澳阒牢沂窃趺聪氲膯幔俊毙跽f,“此時此刻,我感覺自己變得很大,而且我還在一直變大、變大,變得和浩瀚的宇宙一樣大。但我并不是像氣球一樣被吹大的,因為那樣一定會在某個時刻爆掉。我所感覺的變大,是一種很輕松很自然的感覺,沒有任何被拉伸的不適感。仿佛我就是空氣,一股四散漂流的空氣。最后,我不僅僅是宇宙的一部分,我就是宇宙的全部,所有的星星都與我同在。你能想象這種感覺嗎?”";
[alertVC addAtionButtonTitle:@"取消" Handle:^(UIButton *sender) {
NSLog(@"點擊了取消");
}];
[self presentViewController:alertVC animated:YES completion:nil];
自定義彈框中部的內(nèi)容
RAlertViewController *alertVC = [[RAlertViewController alloc] init];
alertVC.titleString = @"提示";
UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 300, 100)];
UILabel *lable = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, CGRectGetWidth(view.frame), 30)];
lable.text = @"自定義中部的內(nèi)容";
[view addSubview:lable];
UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, CGRectGetHeight(lable.frame), 50, 50)];
imageView.image = [UIImage imageNamed:@"heart"];
[view addSubview:imageView];
alertVC.middleView = view;
[alertVC addAtionButtonTitle:@"取消" Handle:^(UIButton *sender) {
NSLog(@"點擊了取消");]
}];
[self presentViewController:alertVC animated:YES completion:nil];
帶有UITextField的彈框
RAlertViewController *alertVC = [[RAlertViewController alloc] init];
alertVC.titleString = @"登錄";
// alertVC.messageString = @"請輸入下面信息";
[alertVC addTextFieldWithHandler:^(UITextField *textField) {
textField.placeholder = @"請輸入手機號";
}];
[alertVC addTextFieldWithHandler:^(UITextField *textField) {
textField.placeholder = @"請輸入密碼";
}];
[alertVC addTextFieldWithHandler:^(UITextField *textField) {
textField.placeholder = @"請輸入驗證碼";
}];
[alertVC addAtionButtonTitle:@"取消" Handle:^(UIButton *sender) {
NSLog(@"點擊了取消");
}];
[self presentViewController:alertVC animated:YES completion:nil];
AlertView說明
titleString:如果不添加則不顯示
messageString:如果不添加則不顯示
ationButton:如果不添加則不顯示
上述的內(nèi)容如果定義就會顯示如果不定義就不會顯示。和UIAlertViewController功能類似
ActionSheet主要用于分享
分享內(nèi)容較少
RActionSheetItem *item1 = [RActionSheetItem actionSheetItemWithTitle:@"微博分享" image:[UIImage imageNamed:@"chat"] handler:^{
NSLog(@"微博分享");
}];
RActionSheetItem *item2 = [RActionSheetItem actionSheetItemWithTitle:@"微信分享" image:[UIImage imageNamed:@"weibo"] handler:^{
NSLog(@"微信分享");
}];
RActionSheetItem *item3 = [RActionSheetItem actionSheetItemWithTitle:@"朋友圈分享" image:[UIImage imageNamed:@"friend"] handler:^{
NSLog(@"朋友圈分享");
}];
RActionSheetViewController *actionSheetVC = [[RActionSheetViewController alloc] initWithTitle:@"選擇分享" Message:nil Items:@[item1,item2,item3]];
[self presentViewController:actionSheetVC animated:YES completion:nil];
分享內(nèi)容較多
RActionSheetItem *item1 = [RActionSheetItem actionSheetItemWithTitle:@"微博分享" image:[UIImage imageNamed:@"heart"] handler:^{
NSLog(@"微博分享");
}];
RActionSheetViewController *actionSheetVC = [[RActionSheetViewController alloc] initWithTitle:@"選擇分享" Message:@"...翻牌子辣..." Items:@[item1,item1,item1,item1,item1,item1,item1,item1,item1,item1,item1,item1,item1,item1,item1,item1,item1,item1]];
[self presentViewController:actionSheetVC animated:YES completion:nil];
ActionSheet說明
title如果不添加就不顯示
message如果不添加就不顯示
最后
demo寫的好糙啊~~~~~~
// TODO:
- 添加Toast類型的條形提示
- 添加更多的轉(zhuǎn)換效果
- 自定義更多類型
- 添加更多調(diào)用的方法比如用View 調(diào)用,用VC調(diào)用,用Window調(diào)用
// FIXME: - 將frame的布局改成NSLayoutConstraint
- 把代碼改的好看一點
代碼在這里Reiko github,如果不符合要求可根據(jù)需要修改