gpt4 book ai didi

ios - 如何使用图像和按钮调整大小和自定义 AlertView

转载 作者:行者123 更新时间:2023-11-29 11:09:38 25 4
gpt4 key购买 nike

我首先使用“[UIAlertView alloc] initWithTitle:”来调整大小和自定义带有图像的AlertView,但失败了。

然后我使用以下代码,一切正常(调整了 alertView 的大小并带有图像),但就是没有按钮来关闭 alertView。卡在这里半天。请帮忙,谢谢!

UIAlertView* find = [[[UIAlertView alloc] init]initWithFrame:CGRectMake(0,0,300,420)];
[find setDelegate:self];
[find setTitle:@"Sample Alert"];
[find setNeedsLayout];

UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(220, 10, 80, 80)];

NSString *path = [[NSString alloc] initWithString:[[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"111.png"]];
UIImage *bkgImg = [[UIImage alloc] initWithContentsOfFile:path];
[imageView setImage:bkgImg];
[bkgImg release];
[path release];

[find addSubview:imageView];
[imageView release];

[find show];
find.frame = CGRectMake(0,0,300,200);

[find release];

最佳答案

UIAlertView 不是以这种方式初始化的。通常你使用 initWithTitle:message:delegate:cancelButtonTitle:otherButtonTitles: 初始化一个 UIAlertView

您可以尝试使用 [find addButtonWithTitle:@"button 1"]; 。您还需要实现 UIAlertView Delegate与按钮交互。

如果这不起作用,如果您正在寻找经过大量修改的外观,我建议实现您自己的自定义 View 。

希望这对您有所帮助。

关于ios - 如何使用图像和按钮调整大小和自定义 AlertView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12119383/

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