我想要在點擊按鈕時,設置默認圖片高亮顯示。按鈕代碼如下,在執行這段代碼時,怎麼設置另一個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;
}
假設你已經將需要高亮的圖片引用了
- (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;
}
需要將圖片添加到資源。