title: Making a custom Button using a UIView or overriding UIButton?
body: <p>I need to generate a custom button through code, this is how i am currently doing it.</p>
  
  <pre><code>-(void) initialiseButtons 
  {
      int ypos = playerImage.frame.origin.y + playerImage.frame.size.height + 8;
      for(int i=0; i&lt;totalButtons; i++) 
      {       
          UIButton *newButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];    
          [newButton setFrame:CGRectMake(20, ypos, 220, 30)];
          newButton.tag = 10 + i;
          [newButton addTarget:self action:@selector(statTapped:) forControlEvents:UIControlEventTouchUpInside];
          [self.frontView addSubview:newButton];
          ypos += 30 + 7;
      }
  }
  </code></pre>
  
  <p>This creates the blank buttons perfectly through code, gives them a tag and assigns an callback function on touchUpInside.</p>
  
  <p>The custom button needs to be able to handle showing an image when pressed down.
  It needs to be able to draw 2 pieces of Text. 1 aligned to the left hand side of the button and 1 aligned to the righthand side of the button.</p>
  
  <p>My boss suggested instead of buttons I use a View. I dont understand how this will work. When i start thinking about it, i think it would require having a viewcontroller dedicated to the buttons. And some draw method? It sounds complicated and I am not grasping how it can be done.</p>
  
  <p>Is there a simpler method by making a custom class overriding UIButton? I made a simple test class earlier but nothing was drawn in the buttons locations when I used them in place of the Normal UIButton class. I expected i would see the buttonUp.png drawn.</p>
  
  <pre><code>#import &lt;Foundation/Foundation.h&gt;
  #import &lt;UIKit/UIKit.h&gt;
  
  @interface CardButton : UIButton {
  }
  @end
  
  
  #import "CardButton.h"
  #import &lt;UIKit/UIKit.h&gt;
  @implementation CardButton
  - (id)initWithFrame:(CGRect)frame 
  {
      if (self = [super initWithFrame:frame]) 
      {
          [self setImage:[UIImage imageNamed:@"buttonUp.png"] forStates:UIControlStateNormal];
          self.adjustsImageWhenHighlighted = YES;
      }
      return self;
  }
  @end
  </code></pre>
  
  <p>Anybody able to give me some pointers on this? I'm pretty blocked at the moment. Have been reading some various other threads related to buttons but nothing that made it clear in my head how to tackle the problem</p>