2013-04-08 1 views
0

У меня есть конструктор UIAlert, и я хотел бы добавить изображение между заголовком и кнопкой. Это мой код:Добавить изображение в UIAlertBuilder

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?

+0

вам необходимо применить трансформацию. – yunas

+0

@yunas, не могли бы вы объяснить это немного? – user1256477

+1

любезно см. Обновленный ответ – yunas

ответ

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]; 
+0

Я пробовал ваше решение, но у меня тот же результат, отредактировал мой пост с результатом – user1256477

+1

хорошо, вам нужно изменить ширину и высоту изображения. – yunas

+0

Я изменил размер изображения, и до сих пор не работает, отредактировал мое сообщение – user1256477

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]; 
Смежные вопросы