2 mapmapm MapMapM 于 2013.06.24 14:08 提问

点击按钮图片高亮显示

我想要在点击按钮时,设置默认图片高亮显示。按钮代码如下,在执行这段代码时,怎么设置另一个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;
  }

1个回答

g989_1314125
g989_1314125   2013.06.24 14:54
已采纳

假设你已经将需要高亮的图片引用了

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

需要将图片添加到资源。

Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!