gpt4 book ai didi

ios - 如何在UIAlertView的中心添加UIActivityIndi​​catorView?

转载 作者:行者123 更新时间:2023-12-01 17:16:19 25 4
gpt4 key购买 nike

作为标题,我想在UIAlertView实例的中心添加一个UIActivityIndi​​catorView实例。这是我的代码:

    alertView  = [[UIAlertView alloc]initWithTitle:@"Processing" message:@"" delegate:nil cancelButtonTitle:nil otherButtonTitles:nil, nil];

CGRect screenRect = [[UIScreen mainScreen] bounds];
indicator = [[UIActivityIndicatorView alloc]initWithFrame:CGRectMake(screenRect.size.width/2, screenRect.size.height/2,50,50)];
[alertView addSubview: indicator];
[indicator startAnimating];
[alertView show];

我看到的只是alertView。我有没有犯错?

最佳答案

当您将指示器的宽度和高度设置为alertview框架中的x和y位置时,您已经忘记考虑指示器的宽度和高度。

indicator = [[UIActivityIndicatorView alloc]initWithFrame:CGRectMake(roundf((screenRect.size.width - 50) / 2), roundf((screenRect.size.height - 50) / 2),50,50)];

编辑:这是我通常使用的确切名称:(别忘了发布内容,等等)
UIAlertView *alert = [[UIAlertView alloc] initWithTitle: @"Loading..." message: nil delegate:self cancelButtonTitle: nil otherButtonTitles: nil];
UIActivityIndicatorView *progress= [[UIActivityIndicatorView alloc] initWithFrame: CGRectMake(125, 50, 30, 30)];
progress.activityIndicatorViewStyle = UIActivityIndicatorViewStyleWhiteLarge;
[alert addSubview: progress];
[progress startAnimating];
[alert show];

关于ios - 如何在UIAlertView的中心添加UIActivityIndi​​catorView?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15391344/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com