将图像添加到UIAlertBuilder

时间:2013-04-08 08:14:35

标签: objective-c uiimageview uialertview

我有一个UIAlert构建器,我想在标题和按钮之间添加一个图像。这是我的代码:

UIAlertView *pull = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"pull_wire", nil)
                                    message:nil
                                    delegate:nil
                                    cancelButtonTitle:NSLocalizedString(@"continue_text", nil)
                                    otherButtonTitles:nil];

UIImageView *imageView = [[UIImageView alloc] initWithImage: [UIImage imageNamed: @"cable.png"]];

[pull addSubview:imageView];
[pull show];

但是图像显示在UIAlertView的顶部。

使用@yunas解决方案:

enter image description here

可能是图片太大了吗?

调整图片大小:

enter image description here

如何在UIAlert中获取它?

2 个答案:

答案 0 :(得分:2)

UIAlertView *pull = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"pull_wire", nil)
                                message:@"\n\n\n\n\n\n\n\n\n\n\n\n"
                                delegate:nil
                                cancelButtonTitle:NSLocalizedString(@"continue_text", nil)
                                otherButtonTitles:nil];

答案 1 :(得分:1)

UIAlertView *pull = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"pull_wire", nil)
                                    message:nil
                                    delegate:nil
                                    cancelButtonTitle:NSLocalizedString(@"continue_text", nil)
                                    otherButtonTitles:nil];

[pull show];

UIImageView *imageView = [[UIImageView alloc] initWithImage: [UIImage imageNamed: @"cable.png"]];
    CGRect frame = imageView.frame;
    frame.origin = CGPointMake(0, 80); // set the origin here
    frame.size = CGSizeMake(90,40);//ANY SIZE that you want, but remember if you want the alertview to be big in size you need to apply transformation on the pull (ALERTVIEW)
[imageView setFrame:frame];
[pull addSubview:imageView];