0

I would like to change the default UIImage to highlighted when a UIButton is pressed. So when the below code is executed, I would like to change the UIImage of another to highlighted.

- (IBAction)buttonOperationPressed:(id)sender {
    if (currentOperation == 0) result = currentNumber;
    else {
        switch (currentOperation) {
            case 1:
                result = result + currentNumber;
                break;
            case 2:
                result = result - currentNumber;
                break;
            case 3:
                result = result * currentNumber;
                break;
            case 4:
                result = result / currentNumber;
                break;
            case 5:
                currentOperation = 0;
                break;
        }
    }
        currentNumber = 0;
        calculatorScreen.text = [NSString stringWithFormat:@"%g", result];
        if ([sender tag] ==0) result=0;
        currentOperation = [sender tag];
        userInTheMiddleOfEnteringDecimal = NO;
  }
icodebuster
  • 8,890
  • 7
  • 62
  • 65
user2318472
  • 15
  • 1
  • 3
  • Not sure what you mean by 'highlighted'. Make it brighter? You can always set the `UIImageView`'s `image` property to something else when the button is tapped... – Khanh Nguyen Jun 22 '13 at 15:38
  • Oops I think I misunderstood you question. Ignore my previous comment please. Follow this [SO link](http://stackoverflow.com/questions/5592646/uibutton-set-image-for-selected-highlighted-state) – Khanh Nguyen Jun 22 '13 at 15:45

2 Answers2

0

UIImage does not have a highlighted state (check the documentation: http://developer.apple.com/library/ios/#documentation/UIKit/Reference/UIImage_Class/Reference/Reference.html)

Amandir
  • 679
  • 1
  • 7
  • 20
0

I am assuming that you have the reference of the imageView which You want to highlighed

- (IBAction)buttonOperationPressed:(id)sender{
    UIImageView *imageView = [UIImageView alloc] init];
    imageView.frame = CGRectMake(0,0,200,200);  //Change frame according to your Need
    NSString *path = [[NSBundle mainBundle] pathForResource:@"highlighted_image" ofType:@"png"];
    UIImage *image = [[UIImage alloc] initWithContentsOfFile:path];
    imageView.image = image;
    }

You have to add the image in your resource..

bhawesh
  • 1,310
  • 2
  • 19
  • 57