user1256477
user1256477

Reputation: 11201

add an image to an UIAlertBuilder

I have an UIAlert builder and i would like to add an image between the title and the button. This is my code:

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

But the image is shown on top of the UIAlertView.

With @yunas solution:

enter image description here

Could be the image is too big?

Resizing the image:

enter image description here

how can I get it inside the UIAlert?

Upvotes: 0

Views: 76

Answers (2)

yunas
yunas

Reputation: 4163

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

Upvotes: 1

Muhammad Adil
Muhammad Adil

Reputation: 300

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

Upvotes: 2

Related Questions