0

I have a UIImageView that I'm adding to a UIAlertController. I want the image view to be smack dab in the middle of the screen, but when toying around with the CGRectMake coordinates, I'm finding that my y value only appears on screen if given a negative coordinate.

var alert = UIAlertController()
let myImage = UIImage(named: "image")
var imageView = UIImageView(frame:CGRectMake((UIScreen.mainScreen().bounds.width/2) - 60, -300, 120, 120))
imageView.image = myImage
alert.view.addSubview(imageView)

alert.addAction(UIAlertAction(title: "OK", style: UIAlertActionStyle.Default, handler: nil))
self.presentViewController(alert, animated: true, completion: nil)

Why do I need a negative y value coordinate in my var imageView declaration to show on screen? If the alert.view.bounds = (0,0,335,667) then shouldn't a negative y value mean the view will appear off screen?

Otherwise, am I just doing something wrong?

slider
  • 2,736
  • 4
  • 33
  • 69
  • 2
    [“The UIAlertController class is intended to be used as-is and does not support subclassing. The view hierarchy for this class is private and must not be modified.”](https://developer.apple.com/library/ios/documentation/UIKit/Reference/UIAlertController_class/) You are doing something explicitly forbidden by the documentation. So yes, you're just doing something wrong. – rob mayoff Jul 14 '15 at 19:31
  • What would my alternative be? – slider Jul 14 '15 at 19:35
  • Google? Custom alert view like [this one](https://github.com/wimagguc/ios-custom-alertview) for example ... – zrzka Jul 14 '15 at 19:39
  • Can I use that in Swift? – slider Jul 14 '15 at 23:02

0 Answers0