title: How can i increase the button width dynamically depends on the text size in iphone?
body: <p>I have created 10 buttons programmatically and set the titles in the button. Now i want to increase the button frame size dynamically,its depends on the text.</p>
  
  <p>I given some conditions and set the frame size. but how can i set the exact frame size depends on the text(get the text dynamically).</p>
  
  <p>Here my sample code is,</p>
  
  <pre><code>     float x=0, y=0, w, h=20;
  
      for(int i = 100; i &lt; 110; i++)
       {
           btn = [[UIButton buttonWithType:UIButtonTypeRoundedRect] retain];
  
           UIImage * img = [UIImage imageNamed:@"Round_Rect4.png"];
  
          [btn setBackgroundImage:img forState:UIControlStateSelected];
  
          titleString = [titleArray objectAtIndex:i-100];  // get button title
  
          if([titleString length] &lt;= 5)
          {
              w = 50;
              btn.frame = CGRectMake(x,y,w,h); 
  
              x = x + 70;
          }
  
          if (([titleString length] &gt;= 6) &amp;&amp; ([titleString length] &lt;=10))
         {
               w = 70;
  
               btn.frame = CGRectMake(x,y,w,h); 
  
               x = x + 90;
         } 
  
         if(([titleString length] &gt;= 11) &amp;&amp; ([titleString length] &lt;=15))
         {
               w = 105;
               btn.frame = CGRectMake(x,y,w,h); 
  
               x = x + 120;
  
         }
  
         if([titleString length] &gt;= 16)
         {
               w = 120;
               btn.frame = CGRectMake(x,y,w,h); 
  
               x = x + 140;
  
         }
  
          [btn setTitle:titleString forState: UIControlStateNormal];
  
          [btn setTag:i];
  
          [self.view addSubview:btn];
  </code></pre>
  
  <p>}</p>
  
  <p>see the example image,</p>
  
  <p><a href="http://www.freeimagehosting.net/uploads/b6e0f234dc.png" rel="noreferrer">image-2 http://www.freeimagehosting.net/uploads/b6e0f234dc.png</a>
   <a href="http://www.freeimagehosting.net/uploads/6b3daab12f.png" rel="noreferrer">image-1 http://www.freeimagehosting.net/uploads/6b3daab12f.png</a></p>
  
  <p>So is this possible to set the exact button frame size which depends on the text?, plz guide me.</p>
  
  <p>Thanks</p>