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

标签 ios image button alertview

我首先使用“[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/

相关文章:

ios - 检索图像内存使用情况

ios - React-native iOS : Cocoapods could not find compatible version for pod "Firebase/CoreOnly" ,"Google-Maps-iOS-Utils" & "GoogleMaps"

python - 图像中的对象检测 (HOG)

css - 当图像左对齐时 <ol><li> 位置为奇数

Java NetBeans : How do I make the button submit after I press “Enter” ?

JavaFX——按键事件被按钮中断

ios - 使用 UIViewController 展开可选值

javascript - 在 ios ionic 应用程序中使用 javascript promises

java - 获取图像的高度和宽度时,ImageObserver 字段的用途是什么?

jQuery - 悬停时更改颜色的亮度