通过xib创建一个自定义弹窗:
该弹窗可以自定义view的背景,颜色,字体的大小,颜色调整
方便编写,调用简单:
LoginAlertTableView.h
LoginAlertTableView.m
import "LoginAlertTableView.h"
@interface LoginAlertTableView()
@property (weak, nonatomic) IBOutlet UILabel *titleLabel;
@property (weak, nonatomic) IBOutlet UIView *contetView;
@property (nonatomic, copy) void(^Block)(void);
@end
@implementation LoginAlertTableView
static LoginAlertTableView *manager = nil;
+(instancetype)shareManager
{
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
manager= [[[NSBundle mainBundle] loadNibNamed:@"LoginAlertTableView" owner:self options:nil] lastObject];
});
return manager;
}
//展示
-(void)show
{
self.hidden = NO;
CGAffineTransform transform = CGAffineTransformScale(CGAffineTransformIdentity,1.0,1.0);
self.contetView.transform = CGAffineTransformScale(CGAffineTransformIdentity,0.2,0.2);
self.contetView.alpha = 0;
self.frame=CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT);
[[UIApplication sharedApplication].keyWindow addSubview:self];
[UIView animateWithDuration:0.3 delay:0.1 usingSpringWithDamping:0.5 initialSpringVelocity:10 options:UIViewAnimationOptionCurveLinear animations:^{
self.contetView.transform = transform;
self.contetView.alpha = 1;
self.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:.3f];
} completion:^(BOOL finished) {
[self performSelector:@selector(dismissAlert:) withObject:self afterDelay:1.0];
}];
}
//隐藏
-(void)dismissAlert:(UIView *)view{
[self dismiss];
if (self.Block) {
self.Block();
}
}
//隐藏
-(void)dismiss
{
[UIView animateWithDuration:0.3 animations:^{
self.contetView.transform=CGAffineTransformMakeScale(0.02, 0.02);
} completion:^(BOOL finished) {
[self removeFromSuperview];
}];
}
+(LoginAlertTableView *)title:(NSString *)title show:(void(^)(void))block{
LoginAlertTableView *view = [LoginAlertTableView shareManager];
view.titleLabel.text = title;
view.Block = block;
[view show];
return view;
}
- (IBAction)cancelBtnClick:(id)sender {
[self dismiss];
}
@end