我正在制作文字游戏,有两个可能的标签“完美!”仅在分数为100且“正确!”时显示当分数低于100时,
但我无法打电话给“正确!”当分数低于100时标记!
- (IBAction)btncheck:(id)sender {
NSString *answer = [_textbox.text stringByReplacingOccurrencesOfString:@" " withString:@""];
if([answer isEqualToString:@""]){
}
else
if ([answer isEqualToString:@"q"]) {
_keyboard.hidden = YES;
_textXclear.hidden = YES;
//Perfect button
[_closeone setHidden:NO];
[_wrongone setHidden:YES];
score = MAX (score +100, 0);
[scoreLabel setText:[NSString stringWithFormat:@"score: %d", score]];
coins = coins +5;
if (score == 100) coins = 8;
if (score == 0) coins = 0;
if (score == 4) coins = 4;
if (score == 3) coins = 3;
if (score == 2) coins = 2;
if (score == 1) coins = 1;
[coinsLabel setText:[NSString stringWithFormat:@"%d", coins]];
}
else {
[_wrongone setHidden:NO];
score = MIN(score -5, 0);
[scoreLabel setText:[NSString stringWithFormat:@"score: %d", score]];
// animation that shakes the image (qimage)
closeonechange.text = @"Correct!";
}
标签名为
closeonechange.text = "Correct!";
如果分数低于100,我将如何调用它来显示,所以99&下面必须显示“正确!”标签
答案 0 :(得分:0)
在你的if else语句中隐藏/显示它:
if ([answer isEqualToString:@"q"]) { //Score >100 display perfect
// Your code...
closeonechange.text = "Perfect";
}
else { //Score < 100 display correct
// Your code...
closeonechange.text = "Correct";
}
//扩展
如果您只使用一个标签来显示文字而不是隐藏/显示只需更改文字,请参阅上面的编辑。
答案 1 :(得分:0)
试试这个,
if([answer isEqualToString:@""]){
...
}
else {
...
}
if (score < 100) {
closeonechange.text = "Correct!";
} else {
closeonechange.text = //set else condition text
}