1

I know this is frequently asked question that, how to display another control rather message in uiAlertView. I have an app which have image in my view and when user tap on that image I want to enlarge it. So, I have option that popup it in uialertview with same image with enlargement. when I try it as well, but not with proper solution.

below is my code

UIAlertView *alert = [[UIAlertView alloc] initWithTitle:NULL message:@"\n\n\n\n\n\n\n\n\n\n\n\n\n" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
UIImage *image = [UIImage imageNamed:@"GM00132002062125.png"];
UIImageView *imageView = [[UIImageView alloc] initWithImage:image];
CGFloat imageHeight = 250;
CGFloat imageWidth = imageHeight * image.size.width / image.size.height;
imageView.frame = CGRectMake(floor((284 - imageWidth)/2), 47, imageWidth, imageHeight);
[alert addSubview:imageView];
[alert show];

here I have to give \n\n for message,

enter image description here

If you can see it overlap on OK if I give more \n in message

enter image description here

There is no particular solution for this

Thanks

Manish Jain
  • 842
  • 1
  • 11
  • 29

1 Answers1

1

use this bellow code...

    UIImageView *imageView = [[UIImageView alloc] initWithFrame:setYourFrameHere];

    NSString *imgPath = [[NSString alloc] initWithString:[[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"GM00132002062125.png"]];
    UIImage *yourImage = [[UIImage alloc] initWithContentsOfFile:imgPath];
    [imageView setImage:yourImage];
    [yourImage release];
    [imgPath release];

    [alert addSubview:imageView];
    [imageView release];

    [alert show];
    [alert release];

UPDATE:

For center the image or some customview in our view i use this type of bellow code..try this...

myCustomView.frame = CGRectMake(floorf(backgroundView.size.width - customView.size.width / 2.0f), 0.0, myCustomView.size.widht, myCustomView.size.height);
Paras Joshi
  • 20,427
  • 11
  • 57
  • 70
  • Thanks for reply Paras Joshi, but I think you've to check my code. It's much same as yours. Rather I just put proper size specifications. – Manish Jain Jan 07 '13 at 11:43
  • try to center the image with my above code may be its work for you just use imageView to center in alertview just change some code.. and it will work.. – Paras Joshi Jan 07 '13 at 11:46
  • Thanks, CGFloat imageHeight = 250; CGFloat imageWidth = imageHeight * image.size.width / image.size.height; imageView.frame = CGRectMake(floor((284 - imageWidth)/2), 47, imageWidth, imageHeight); with this I'm doing same thing. – Manish Jain Jan 07 '13 at 11:52
  • @Deer why you give this \n more than time?? for get image center right?? – Paras Joshi Jan 07 '13 at 11:52
  • that is not for image center that is for make space height wise for uialertview. and I'm not give 9 \n. That's just for example. And my meaning is not with this image only. Actually my image size can be more than this. In that situation our this code will not work. That's why I want some proper solution of this Paras. – Manish Jain Jan 07 '13 at 12:01
  • ya ya now i understand that what you want.. here you see overlap the image with message box if you give more than \n and also image display out of uialertview if \n is lessthen the height of image,... right?? – Paras Joshi Jan 07 '13 at 12:02
  • yes, this is just example through which I want to ask you that if my image size is 300x300. How can I use this code because here image height is more that uialertview height. Now got it...!?! – Manish Jain Jan 07 '13 at 12:06
  • @Deer hey if you use custom popup instead of alertview then its also very useful and also easy to use for you.. – Paras Joshi Jan 07 '13 at 12:16
  • with custom popup, you can't be sure that app will pass in app review, otherwise I already go with that option...!?! – Manish Jain Jan 07 '13 at 12:41
  • let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/22315/discussion-between-deer-and-paras-joshi) – Manish Jain Jan 07 '13 at 12:47