Create UIButton/button with images

by alex 13. February 2009 10:31

UIButton *playButton = [[UIButton buttonWithType:UIButtonTypeRoundedRect] retain];

playButton.frame = CGRectMake(110.0, 360.0, 100.0, 30.0);

[playButton setTitle:@"Play" forState:UIControlStateNormal];

playButton.backgroundColor = [UIColor clearColor];

[playButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal ];

 

UIImage *buttonImageNormal = [UIImage imageNamed:@"blueButton.png"];

UIImage *strechableButtonImageNormal = [buttonImageNormal stretchableImageWithLeftCapWidth:12 topCapHeight:0];

[playButton setBackgroundImage:strechableButtonImageNormal forState:UIControlStateNormal];

 

UIImage *buttonImagePressed = [UIImage imageNamed:@"whiteButton.png"];

UIImage *strechableButtonImagePressed = [buttonImagePressed stretchableImageWithLeftCapWidth:12 topCapHeight:0];

[playButton setBackgroundImage:strechableButtonImagePressed forState:UIControlStateHighlighted];

 

[playButton addTarget:self action:@selector(playAction:) forControlEvents:UIControlEventTouchUpInside];

[self.view addSubview:playButton];

Currently rated 5.0 by 3 people

  • Currently 5/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags: , ,

General

Powered by BlogEngine.NET 1.4.5.0
Theme by Mads Kristensen