title: iOS- How can I get UIAlertView width with customize and put the UILabel to center
body: <p>I was custom the <code>UIAlertView</code>, I need add some component to the <code>alertView</code> (like label, tableview).</p>
  
  <p>But I have a question. I need to know the alertView's width.</p>
  
  <p>I try to add <code>self.frame.size.width</code>, but I just got the <code>0.000000</code>.</p>
  
  <p>How can I get the alertView's width?</p>
  
  <p>I will calculate to put the subview at, and put the <code>UILabel</code> to subview to center. My partial code below:</p>
  
  <p><strong>.h file:</strong></p>
  
  <pre><code> #import &lt;UIKit/UIKit.h&gt;
  
   @interface CustomTableViewAlert : UIAlertView
  
   -(instancetype)initWithTitle:(NSString *)title message:(NSString *)message delegate:(id)delegate cancelButtonTitle:(NSString *)cancelButtonTitle otherButtonTitles:(NSString *)otherButtonTitles, ...;
  
  
   @end
  </code></pre>
  
  <p><strong>.m file:</strong></p>
  
  <pre><code>   #import "CustomTableViewAlert.h"
  
    ...
     @implementation CustomTableViewAlert
  
  
   -(instancetype) initWithTitle:(NSString *)title message:(NSString *)message delegate:(id)delegate cancelButtonTitle:(NSString *)cancelButtonTitle otherButtonTitles:(NSString *)otherButtonTitles, ...
   {
     self = [super initWithTitle:title message:message delegate:self      cancelButtonTitle:cancelButtonTitle otherButtonTitles:otherButtonTitles, nil];
  
  if( self )
  {
  
   NSLog(@"=====self.frame.size.width:%f",self.frame.size.width);
   // ^^^^^^^^^^^^^^ I got 0.000000
  
      CGSize screenSize = [UIScreen mainScreen].bounds.size;
  
      float showInAlertWidth = screenSize.width - 100;
      float showInAlertHeight = 150;
  
      CGSize textSize = [[notFoundDeviceLabel text] sizeWithAttributes:@{NSFontAttributeName:[notFoundDeviceLabel font]}];
  
      CGFloat strikeWidth = textSize.width;
      CGFloat strikeHeight = textSize.height;
      [notFoundDeviceLabel setFrame:CGRectMake(0, 0, screenSize.width, showInAlertHeight)];
  
      notFoundDeviceLabel.text = @"No Device found";
      notFoundDeviceLabel.textAlignment = NSTextAlignmentCenter;
  
      // new container view
      containerView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, screenSize.width, showInAlertHeight)];
      containerView.backgroundColor = [UIColor yellowColor];
  
      [containerView addSubview: notFoundDeviceLabel];
  }
  
  return self;
   }
  </code></pre>
  
  <p>Thank you very much.</p>