Rob Johansen
Rob Johansen

Reputation: 5164

How to position a UIAlertController's view?

I'm writing an app in Swift, targeting iOS 8. Does anyone know whether it's possible to programmatically position the alerts that are displayed via UIAlertController? The documention makes no mention of position or location, so I tried setting the controller's view.frame property to a new CGRect, but alerts still appearing dead center.

Upvotes: 1

Views: 4995

Answers (1)

Dreaming In Binary
Dreaming In Binary

Reputation: 1287

The alert view, by design, shows right in the center. This is because the experience is intended to be familiar and simple for the end user. In the documentation for UIAlertController it also notes:

The view hierarchy for this class is private and must not be modified.

If you wish to manipulate the placing of the frame, you've got several options that use a plain old UIView/UIViewController. Here is one I've used where you can do what you want that's written in swift: https://github.com/vikmeup/SCLAlertView-Swift

Upvotes: 3

Related Questions