Ios 如何使用图像和按钮调整和自定义AlertView
我首先使用“Ios 如何使用图像和按钮调整和自定义AlertView,ios,image,button,alertview,Ios,Image,Button,Alertview,我首先使用“[UIAlertView alloc]initWithTitle:”来调整和自定义带有图像的AlertView,但失败了 然后我使用以下代码,所有代码都可以正常工作(调整了alertView的大小并带有一个图像),但无法使用按钮关闭alertView。在这里呆了半天。请帮忙,谢谢 UIAlertView* find = [[[UIAlertView alloc] init]initWithFrame:CGRectMake(0,0,300,420)]; [find setDel
[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:cancelButtontile:otherButtontiles:
初始化UIAlertView
您可以尝试使用[find addbuttonwhithtitle:@“button 1]”代码>。您还需要实现与按钮交互
如果这不起作用,我建议如果您正在寻找经过大量修改的外观,则实现您自己的自定义视图
希望这有帮助。非常感谢KDaker!仅“[find addButton With title:@“button 1]”;”这就足够了。它可以关闭AlertView。不再需要实现UIAlertView委托来与按钮交互。非常感谢KDaker!仅“[find addButton With title:@“button 1]”;”这就足够了。它可以关闭AlertView。不再需要实现UIAlertView委托来与按钮交互。但有两件事不能令人满意,一是按钮与alertview的左右边缘不对齐。按钮的右边缘超出警报视图的右边缘。虽然我调整了alertView的大小并放大了它,但该按钮仍然不在alertView中。有没有办法调整按钮的大小?另一件不令人满意的事情是,alertView在弹出后会抖动一次。UIAlertView不能让您控制它的按钮框架。老实说,我不建议过多地定制UIAlertView,因为如果你提交到应用商店,你可能会被苹果拒绝。你能发布一个你拥有的和你想要实现的截图吗?巧合的是,我也意识到我应该发布一个截图。到目前为止,被苹果拒绝的风险已经太大了吗?抱歉,我试图发布屏幕截图,但失败了。请查看这里的截图,谢谢!如果你加一条短信,它就会按下按钮。但我还是看到了你想要达到的目标。。。尝试使用initWithTitle
以正常方式初始化alertView,然后仅将图像添加为子视图:[查找添加子视图:myImageView]
,您可能需要在消息中放置任意文本以调整alertView的大小。