iOS升级页面弹框

来源:互联网 发布:mac鼠标指针变大 编辑:程序博客网 时间:2024/05/01 11:09

UIWindow *window = [UIApplicationsharedApplication].keyWindow;

    

    //1.创建一个大View 蒙版 (加在谁的身上)

    UIView *dimView = [[UIViewalloc]initWithFrame:kScreenBounds];

    

    dimView.backgroundColor = [UIColorblackColor];

    dimView.alpha =0.4;

    [window addSubview:dimView];

    

    //2.在蒙版里面放一张 imageView

    

    UIImageView *imageView = [[UIImageViewalloc]initWithImage:[UIImageimageNamed:@"bg"]];

    

    //开启用户交互

    imageView.userInteractionEnabled =YES;

    

    imageView.center = window.center;

    

    [window addSubview:imageView];

    

    //3.imageView里面放一个按钮

    

    UIButton *btn = [[UIButtonalloc]init];

    

    UIImage *image = [UIImageimageNamed: @"close1"];

    [btn setImage:imageforState: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:selfaction:@selector(cancel:)forControlEvents:UIControlEventTouchUpInside];

    

    //5.添加更新文字

    UILabel* updateTitle = [[UILabelalloc]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 = [[UITextViewalloc]initWithFrame:CGRectMake(imageView.bounds.size.width/2.0-80,190, 180,100)];

    updateText.backgroundColor = [UIColorwhiteColor];

    updateText.editable =NO;

    updateText.text = messageStr;

    NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStylealloc] init];

    paragraphStyle.lineSpacing =3; //行距

    

    NSDictionary *attributes =@{ NSFontAttributeName:[UIFontsystemFontOfSize:15],NSParagraphStyleAttributeName:paragraphStyle,NSForegroundColorAttributeName:LColor(137,137, 137)};

    

    updateText.attributedText = [[NSAttributedStringalloc]initWithString: updateText.textattributes:attributes];

    [imageView addSubview:updateText];

    

    //    UIButton* updateNowBtn = [[UIButton alloc]initWithFrame:CGRectMake(imageView.bounds.size.width/2.0-60, 300, 120, 30)];

    UIButton* updateNowBtn = [UIButtonbuttonWithType: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:selfaction:@selector(nowUpdata)forControlEvents:UIControlEventTouchUpInside];

    [updateNowBtn setTitleColor:LColor(255,255, 255)forState:UIControlStateNormal];

    [imageView addSubview:updateNowBtn];

    

    //关联

    _dimView = dimView;

    _imageView = imageView;


-(void)cancel:(uibutton*)btn{


    [UIViewanimateWithDuration:0.5animations:^{

        

        _imageView.alpha =0.1;

        _dimView.alpha =0.1;

        

    } completion:^(BOOL finished) {

        

        [UIViewanimateWithDuration:0.5animations:^{

            [_imageViewremoveFromSuperview];

            [_dimViewremoveFromSuperview];

        }];

        

    }];

}


0 0
原创粉丝点击