iOS升级页面弹框

这篇博客介绍了如何在iOS应用中实现一个升级页面弹窗。通过创建一个黑色半透明的背景视图(dimView),并在其上添加一个包含更新提示信息的imageView,包括一个关闭按钮、更新标题、更新文字和立即更新按钮。通过监听按钮事件来处理用户交互,如取消更新和立即更新操作。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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];

        }];

        

    }];

}


评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值