UIWindow *window = [UIApplication sharedApplication].keyWindow;
//1.创建一个大View 蒙版 (加在 谁的身上)
UIView *dimView = [[UIView alloc]initWithFrame:kScreenBounds];
dimView.backgroundColor = [UIColor blackColor];
dimView.alpha = 0.4;
[window addSubview:dimView];
//2.在蒙版里面 放一张 imageView
UIImageView *imageView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"bg"]];
//开启用户交互
imageView.userInteractionEnabled = YES;
imageView.center = window.center;
[window addSubview:imageView];
//3.在imageView 里面放一个按钮
UIButton *btn = [[UIButton alloc]init];
UIImage *image = [UIImage imageNamed: @"close1"];
[btn setImage:image forState:UIControlStateNormal];
btn.frame = CGRectMake(imageView.bounds.size.width - image.size.width-30, 80, image.size.width, image.size.height);
[imageView addSubview:btn];
//4.监听按钮
[btn addTarget:self action:@selector(cancel:) forControlEvents:UIControlEventTouchUpInside];
//5.添加更新文字
UILabel* updateTitle = [[UILabel alloc]initWithFrame:CGRectMake(imageView.bounds.size.width/2.0-90, 163, 180, 30)];
// updateTitle.backgroundColor = [UIColor greenColor];
updateTitle.text = @"软件更新提示";
updateTitle.textAlignment = NSTextAlignmentCenter;
updateTitle.textColor = LColor(246, 45, 45);
[imageView addSubview:updateTitle];
UITextView* updateText = [[UITextView alloc]initWithFrame:CGRectMake(imageView.bounds.size.width/2.0-80, 190, 180, 100)];
updateText.backgroundColor = [UIColor whiteColor];
updateText.editable = NO;
updateText.text = messageStr;
NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
paragraphStyle.lineSpacing = 3; //行距
NSDictionary *attributes = @{ NSFontAttributeName:[UIFont systemFontOfSize:15], NSParagraphStyleAttributeName:paragraphStyle,NSForegroundColorAttributeName:LColor(137, 137, 137)};
updateText.attributedText = [[NSAttributedString alloc]initWithString: updateText.text attributes:attributes];
[imageView addSubview:updateText];
// UIButton* updateNowBtn = [[UIButton alloc]initWithFrame:CGRectMake(imageView.bounds.size.width/2.0-60, 300, 120, 30)];
UIButton* updateNowBtn = [UIButton buttonWithType:UIButtonTypeCustom];
updateNowBtn.layer.cornerRadius = 3;
updateNowBtn.frame = CGRectMake(imageView.bounds.size.width/2.0-60, 303, 120, 30);
// updateNowBtn.clipsToBounds = YES;
updateNowBtn.backgroundColor = LColor(246, 45, 45);
[updateNowBtn setTitle:@"立即更新" forState:UIControlStateNormal];
[updateNowBtn addTarget:self action:@selector(nowUpdata) forControlEvents:UIControlEventTouchUpInside];
[updateNowBtn setTitleColor:LColor(255, 255, 255) forState:UIControlStateNormal];
[imageView addSubview:updateNowBtn];
//关联
_dimView = dimView;
_imageView = imageView;
-(void)cancel:(uibutton*)btn{
[UIView animateWithDuration:0.5 animations:^{
_imageView.alpha = 0.1;
_dimView.alpha = 0.1;
} completion:^(BOOL finished) {
[UIView animateWithDuration:0.5 animations:^{
[_imageView removeFromSuperview];
[_dimView removeFromSuperview];
}];
}];
}