Advertisement
Guest User

Untitled

a guest
Jul 13th, 2011
480
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. @interface MyButton : UIButton {
  2.     UIButton * button;
  3. }
  4.  
  5. @property (nontoxic, retain) UIButton * button
  6.  
  7. + (MyButton *) buttonWithRect:(CGRect) target: (id) target action: (SEL) action;
  8. - (id) initWithFrame: (CGRect) rect;
  9.  
  10. @end
  11.  
  12. //---------------------------
  13.  
  14. @implementation EventItemButton
  15.  
  16.  
  17. + (MyButton *) buttonWithRect:(CGRect) target: (id) target action: (SEL) action {
  18.  
  19.     MyButton * myButton = [[MyButton alloc] initWithFrame: rect];
  20.     [myButton.button addTarget:target action:action forControlEvents:UIControlEventTouchUpInside];
  21.     return [myButton autorelease];
  22. }
  23.  
  24. - (id) initWithFrame: (CGRect) rect {
  25.     if ((self = [super initWithFrame: rect])) {
  26.        
  27.         UIImage * myImage = [UIImage imageNamed: @"image.png"];
  28.         UIImageView * myImageView = [[UIImageView alloc] initWithImage: myImage];
  29.         myImageView.userInteractionEnabled = YES;
  30.         myImageView.contentMode = UIViewContentModeScaleToFill;
  31.         [myImageView setFrame: CGRectMake(0.0f, 0.0f, self.frame.size.width, self.frame.size.height)];
  32.         [self addSubview: eventImageView];
  33.         [myImageView release];
  34.  
  35.         UILabel * myText = [[UILabel alloc] initWithFrame: <someframe here> ];
  36.         titleText.text = @"Title";
  37.         [self addSubview:titleText];
  38.         [titleText release];
  39.        
  40.  
  41.         button = [[UIButton alloc] initWithFrame: CGRectMake(0.0f, 0.0f, self.frame.size.width, self.frame.size.height)];
  42.         button.backgroundColor = [UIColor clearColor];
  43.         [self addSubview: button];
  44.         [button release];
  45.     }
  46.     return self;
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement