2

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?

Scott Berrevoets
  • 16,921
  • 6
  • 59
  • 80
dkaisers
  • 824
  • 1
  • 8
  • 15
  • 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 Answers3

4

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.

Scott Berrevoets
  • 16,921
  • 6
  • 59
  • 80
0

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.

Firo
  • 15,448
  • 3
  • 54
  • 74
David Berry
  • 40,941
  • 12
  • 84
  • 95
0

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.

Firo
  • 15,448
  • 3
  • 54
  • 74