Home Tutorial Iphone Examples UIButton Highlighted - UIControlStateHighlighted

 
 

Share on Google+Share on Google+
UIButton Highlighted - UIControlStateHighlighted
Posted on: May 3, 2010 at 12:00 AM
Advertisement
In this example we are going to change the image of button while highlighting it. "Highlighted" is the state of control that occurs when touch enters and exits on control.

UIButton Highlighted - UIControlStateHighlighted

In this example we are going to change the image of button while highlighting it. "Highlighted" is the state of control that occurs when touch enters and exits on control.

In this example, we are going to create a UIButton programmatically that will show the button changing on touch up.

Create a button

- (void)drawButton
{
myButton = [UIButton buttonWithType:UIButtonTypeCustom];
myButton.frame = CGRectMake(80, 50, 70, 70); //set frame for button

UIImage *buttonImage = [UIImage imageNamed:@"icon6.png"];
[myButton setBackgroundImage:buttonImage forState:UIControlStateNormal];

[myButton setTitle:@"Ok" forState:UIControlStateNormal];
[myButton addTarget:self action:@selector(buttonClicked:) forControlEvents:UIControlEventTouchUpInside];

[self.view addSubview:myButton];

}

- (void)viewDidLoad {
[super viewDidLoad];

[self drawButton];

}

Write a Button Action, that will change the image on touch up


- (IBAction)buttonClicked:(id)sender
{

UIImage *buttonImage = [UIImage imageNamed:@"home.png"];
[myButton setBackgroundImage:buttonImage forState:UIControlStateHighlighted];

}

On running the application you will find that it changes the image on touch up.

Download Code

Advertisement

Related Tags for UIButton Highlighted - UIControlStateHighlighted:


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: May 3, 2010

Recommend the tutorial

Advertisements Advertisements
 

 

 

DMCA.com