废话不多说了,这个类突发奇想,自己写写的,可用于很多地方的弹窗,我这里做更新的提示框用,需要其他地方用的话在类里面写个delegate应该就可以了!我写的比较简单!直接上代码!
UpdateAlterView.h
//
// UpdateAlterView.h
// MyProject
//
// Created by danggui on 16/7/19.
// Copyright © 2016年 danggui. All rights reserved.
//
#import
@interface UpdateAlterView : UIView
- (void)show:(NSString *)str;
@end
UpdateAlterView.m
//
// UpdateAlterView.m
// MyProject
//
// Created by danggui on 16/7/19.
// Copyright © 2016年 danggui. All rights reserved.
//
#import "UpdateAlterView.h"
#define W CGRectGetWidth([UIScreen mainScreen].bounds)
#define H CGRectGetHeight([UIScreen mainScreen].bounds)
@interface UpdateAlterView ()
@property (nonatomic, strong) UIView *bigView;
@property (nonatomic, strong) UIImageView *lab;
@property (nonatomic, strong) UILabel *text;
@property (nonatomic, strong) NSMutableString *textStr;
@end
@implementation UpdateAlterView
@synthesize lab,text;
- (instancetype)init
{
self = [super init];
if (self) {
self.frame = [UIScreen mainScreen].bounds;
self.backgroundColor = [UIColor colorWithRed:0.0 green:0.0 blue:0.0 alpha:0.5];
self.bigView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, W - 40, 150)];
_bigView.layer.cornerRadius = 10;
_bigView.layer.masksToBounds = YES;
_bigView.backgroundColor = [UIColor whiteColor];
_bigView.center = CGPointMake(W / 2, H / 2);
text = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, CGRectGetWidth(_bigView.frame) - 30, 25)];
text.center = CGPointMake(CGRectGetWidth(_bigView.frame)/2, CGRectGetHeight(_bigView.frame)/2);
text.text = @"";
text.textAlignment = NSTextAlignmentCenter;
[_bigView addSubview:text];
lab = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 80, 80)];
lab.backgroundColor = [UIColor whiteColor];
lab.layer.cornerRadius = 40;
lab.layer.masksToBounds = YES;
[lab setImage:[UIImage imageNamed:@"image5.jpg"]];
lab.center = CGPointMake(self.center.x , self.center.y - CGRectGetHeight(_bigView.frame)/2 + 20);
[self addSubview:_bigView];
[self addSubview:lab];
UIButton *bu1 = [UIButton buttonWithType:UIButtonTypeCustom];
bu1.layer.borderColor = [UIColor lightGrayColor].CGColor;
bu1.layer.borderWidth = .3f;
bu1.bounds = CGRectMake(0, 0, CGRectGetWidth(_bigView.frame)/ 2, 44);
bu1.center = CGPointMake(CGRectGetWidth(_bigView.bounds)/4, CGRectGetHeight(_bigView.bounds) - 44 + 24);
[bu1 setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
[bu1 addTarget:self action:@selector(button1) forControlEvents:UIControlEventTouchUpInside];
[bu1 setTitle:@"取消" forState:UIControlStateNormal];
[_bigView addSubview:bu1];
UIButton *bu2 = [UIButton buttonWithType:UIButtonTypeCustom];
bu2.layer.borderColor = [UIColor lightGrayColor].CGColor;
bu2.layer.borderWidth = .2f;
bu2.bounds = CGRectMake(0, 0, CGRectGetWidth(_bigView.frame)/ 2, 44);
bu2.center = CGPointMake(3 * CGRectGetWidth(_bigView.bounds)/4, CGRectGetHeight(_bigView.bounds) - 44 + 24);
[bu2 setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
[bu2 setTitle:@"确定" forState:UIControlStateNormal];
[bu2 addTarget:self action:@selector(button2) forControlEvents:UIControlEventTouchUpInside];
[_bigView addSubview:bu2];
UILabel *line = [[UILabel alloc]initWithFrame:CGRectMake(0, bu2.frame.origin.y, CGRectGetWidth(_bigView.bounds), 0.5)];
line.backgroundColor = [UIColor colorWithRed:0.8235 green:0.8235 blue:0.8235 alpha:1.0];
[_bigView addSubview:line];
_bigView.transform = CGAffineTransformMakeScale(0, 0);
lab.transform = CGAffineTransformMakeScale(0,0);
}
return self;
}
- (void)button2 {
[self dissmiss];
//ReUploadUrl 为你跳转到AppStore的链接
//#define ReUploadUrl @"itms-apps://itunes.apple.com/WebObjects/MZStore.woa/wa/viewSoftware?id="
//(ps:id=后面的就是你提交appstore审核的那个id,找不到的自行百度)
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:ReUploadUrl]];
}
- (void)button1 {
[self dissmiss];
}
- (void)dissmiss {
[UIView animateWithDuration:.2 animations:^{
[UIView setAnimationCurve:UIViewAnimationCurveEaseIn];
self.alpha = 0;
} completion:^(BOOL finished) {
[self removeFromSuperview];
}];
}
- (void)show:(NSString *)str{
UIWindow *window = [[UIApplication sharedApplication].windows lastObject];
[window addSubview:self];
[UIView animateWithDuration:.3 delay:0 usingSpringWithDamping:0.8 initialSpringVelocity:1 / 0.8 options:0 animations:^{
[UIView setAnimationCurve:UIViewAnimationCurveEaseOut];
// self.alpha = 1;
_bigView.transform = CGAffineTransformIdentity;
lab.transform = CGAffineTransformIdentity;
} completion:^(BOOL finished) {
[text setText:str];
}];
}
@end
使用也很简单
在你需要用到的地方
#import "UpdateAlterView.h"
然后
UpdateAlterView *update = [[UpdateAlterView alloc]init];
[update show:@"有新版本更新哦!"];
就好了
如图: