Add a button with background image


/ Published in: Objective C
Save to your folder(s)



Copy this code and paste it in your HTML
  1. - (void)viewDidLoad {
  2. contentView = [[UIImageView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]];
  3. [contentView setImage:[UIImage imageNamed:@"284.jpg"]];
  4. [contentView setUserInteractionEnabled:YES];
  5. self.view = contentView;
  6. [contentView release];
  7. UIButton *startButton = [[UIButton alloc] initWithFrame:CGRectMake(0.0f, 0.0f, 180.0f, 130.0f)];
  8. [startButton setBackgroundImage:[[UIImage imageNamed:@"squareButton.png"] stretchableImageWithLeftCapWidth:110.0 topCapHeight:0.0] forState:UIControlStateNormal];
  9. [startButton setCenter:CGPointMake(195.0f, 208.0f)];
  10. [startButton addTarget:self action:@selector(playSound:) forControlEvents:UIControlEventTouchUpInside];
  11. [contentView addSubview:startButton];
  12. [super viewDidLoad];
  13. }

URL: http://pointlessprogrammers.com/?p=100

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.