How to add Progress bar to UIAlertController?

后端 未结 4 1346
终归单人心
终归单人心 2021-01-31 21:39

I want to add progress bar in swift iOS 8 UIAlertController. Is this possible? Is there any way to subclass UIAlertController and add progres bar and connect some delegate funct

4条回答
  •  暗喜
    暗喜 (楼主)
    2021-01-31 22:12

    A solution with auto layout:

        UIAlertController *alertCtr = [UIAlertController alertControllerWithTitle:@"Test" message:@"50%" preferredStyle:UIAlertControllerStyleAlert];
        [alertCtr addAction:[UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
            // Do things
        }]];
    
        UIView *alertView = alertCtr.view;
    
        UIProgressView *progressView = [[UIProgressView alloc] initWithFrame:CGRectZero];
        progressView.progress = 0.5;
        progressView.translatesAutoresizingMaskIntoConstraints = false;
        [alertView addSubview:progressView];
    
    
        NSLayoutConstraint *bottomConstraint = [progressView.bottomAnchor constraintEqualToAnchor:alertView.bottomAnchor];
        [bottomConstraint setActive:YES];
        bottomConstraint.constant = -45; // How to constraint to Cancel button?
    
        [[progressView.leftAnchor constraintEqualToAnchor:alertView.leftAnchor] setActive:YES];
        [[progressView.rightAnchor constraintEqualToAnchor:alertView.rightAnchor] setActive:YES];
    
        [self presentViewController:alertCtr animated:true completion:nil];
    

提交回复
热议问题