-1

在我的应用程序中,如果用户计算出的 BMI < 18.50,标签将显示“体重过轻”的正确分类。我想知道我是否可以用图像来做到这一点。

例如,如果用户的 BMI < 18.50,我不希望有多个 UIImageViews 会被隐藏或不隐藏。我想拥有它,以便如果用户 BMI 是某个数字,则 ONE UIImageView 将显示所需的正确图像。

我上面解释的标签代码是:

if ([bmiView.text floatValue] < 18.50) {
    classification.text = @"Underweight";

// Desired code to go here

}
4

1 回答 1

0

假设您为每个 BMI 提供了三个图像,并且您的 imageview 称为 bmiImageView,那么当以编程方式计算 BMI 时,您为什么不直接分配图像。

    if ([bmiView.text floatValue] < 18.50) {
        classification.text = @"Underweight";
        bmiImageView.image = [UIImage imageNamed:@"Underweight.png"];
    } else if ([bmiView.text floatValue] == 18.50) {
        classification.text = @"Perfect Weight";
        bmiImageView.image = [UIImage imageNamed:@"perfectweight.png"];
    } else if ([bmiView.text floatValue] > 18.50) {
        classification.text = @"Overweight";
        bmiImageView.image = [UIImage imageNamed:@"overweight.png"];
    }
于 2013-07-25T04:21:24.013 回答