When creating an UIAlertView in code, the frame and bounds aren't calculated, yet. But even in the delegate method willPresentAlertView, there are still just zeros in the CGRects. Is there a way to determine an UIAlertView's size, or - as I only need its width - is the width of the view predetermined by iOS and the device?
-
Why do you need the size for UIAlertView? I think it is about 300x200 – Ricky May 05 '14 at 14:02
-
I'd like to add an accessoryView where I place a Label on the left and a Switch on the right and to properly arrange those objects, I need the width of the UIAlertView, at least I think. If there is another (better and easier) way, that would be great, too. – dkaisers May 05 '14 at 14:04
-
in iOS 7 you can not get it and in less then iOS 7 width will be 312 – iPatel May 05 '14 at 14:04
3 Answers
In the comments you mention you want to add custom subviews to your alert. I wouldn't recommend this approach, but look at an alternative such as SDCAlertView
(full disclosure: I wrote it).
In any case, the width of an alert is 270 points.

- 16,921
- 6
- 59
- 80
-
Thanks, I'll check it out. Just for clarification, what is the disadvantage of adding an accessoryView to my UIAlertView? – dkaisers May 05 '14 at 14:08
-
1It's undocumented API, so it could break any time Apple releases an update. – Scott Berrevoets May 05 '14 at 14:09
-
See my answer for why you shouldn't add views to a UIAlertView, bottom line, it's because Apple says not to. – David Berry May 05 '14 at 15:59
From the Apple Documentation:
The UIAlertView 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.
Basically, if you need to add elements, you should create your own UIAlertView look-alike. The system class is intended for a very limited range of functionality.

- 15,448
- 3
- 54
- 74

- 40,941
- 12
- 84
- 95
I was wondering about this information too since I am wanted to create a view the same size. The size of the alert style alert for iOS 7-9
is:
{ 270, 144 }
i.e. (270 width
x 144 height
)
I have not tested this on ever device, so there may be some discrepancy, will update if I ever get around to testing them all.

- 15,448
- 3
- 54
- 74