在按下另一个UIButton时将UIImage设置为突出显示

时间:2013-06-22 15:20:30

标签: iphone ios objective-c uiimage

我希望在按下UIButton时将默认UIImage更改为突出显示。因此,当执行以下代码时,我想将另一个的UIImage更改为突出显示。

- (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;
  }

2 个答案:

答案 0 :(得分:0)

UIImage没有突出显示的状态(请查看文档:{​​{3}})

答案 1 :(得分:0)

我假设您有想要高亮显示的imageView的引用

- (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;
    }

您必须在资源中添加图片..