[英]Setting UIImage to highlighted when another UIButton is pressed
我想將默認的UIImage
更改為在按下UIButton時突出顯示。 因此,當執行以下代碼時,我想將另一個的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;
}
UIImage沒有突出顯示狀態(請查看文檔: http : //developer.apple.com/library/ios/#documentation/UIKit/Reference/UIImage_Class/Reference/Reference.html )
我假設您具有要高亮顯示的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;
}
您必須在資源中添加圖像。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.