ios 如何增加UIAlertAction中的Alpha值?

nxagd54h  于 2022-12-15  发布在  iOS
关注(0)|答案(2)|浏览(154)

当我使用AlertControlAction时,它会接管屏幕,直到你按下取消或诸如此类的键。
我想知道有没有办法增加它周围灰色区域的α值?

eyh26e7m

eyh26e7m1#

您可以根据需要设置alpha,这将在任何情况下导致一些透明度。

UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"Alert title" message:@"Alert message" preferredStyle:UIAlertControllerStyleAlert];

UIAlertAction* ok = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:nil];
[alertController addAction:ok];

alertController.view.backgroundColor = [UIColor colorWithWhite:1 alpha:0.6];

[self presentViewController:alertController animated:YES completion:nil];
qaxu7uf2

qaxu7uf22#

我是这样做的:

class alertController : UIAlertController{
       override func viewWillDisappear(_ animated: Bool) {
           super.viewWillDisappear(animated)
           self.presentingViewController?.view.alpha = 1
               
       }
       override func viewWillAppear(_ animated: Bool) {
           super.viewWillAppear(animated)
           self.presentingViewController?.view.alpha = 0.5

}
}

相关问题