编写以下代码的更好方法是什么?有一些条件代码检查 reviewStarsNumber 的 int 值,然后根据结果显示适当的 uiimage。目前它似乎很长,我想象它可以被简化。
谢谢你的帮助
if ([reviewsStarsNumber intValue] == 0) {
UIImage *img = [UIImage imageNamed:@"hstars-0.png"];
[self.reviewStars setImage:img];
}
if ([reviewsStarsNumber intValue] == 10) {
UIImage *img = [UIImage imageNamed:@"hstars-0_5.png"];
[self.reviewStars setImage:img];
}
if ([reviewsStarsNumber intValue] == 20) {
UIImage *img = [UIImage imageNamed:@"hstars-1_0.png"];
[self.reviewStars setImage:img];
}
if ([reviewsStarsNumber intValue] == 30) {
UIImage *img = [UIImage imageNamed:@"hstars-1_5.png"];
[self.reviewStars setImage:img];
}
if ([reviewsStarsNumber intValue] == 40) {
UIImage *img = [UIImage imageNamed:@"hstars-2_0.png"];
[self.reviewStars setImage:img];
}
if ([reviewsStarsNumber intValue] == 50) {
UIImage *img = [UIImage imageNamed:@"hstars-2_5.png"];
[self.reviewStars setImage:img];
}
if ([reviewsStarsNumber intValue] == 60) {
UIImage *img = [UIImage imageNamed:@"hstars-3_0.png"];
[self.reviewStars setImage:img];
}
if ([reviewsStarsNumber intValue] == 70) {
UIImage *img = [UIImage imageNamed:@"hstars-3_5.png"];
[self.reviewStars setImage:img];
}
if ([reviewsStarsNumber intValue] == 80) {
UIImage *img = [UIImage imageNamed:@"hstars-4_0.png"];
[self.reviewStars setImage:img];
}
if ([reviewsStarsNumber intValue] == 90) {
UIImage *img = [UIImage imageNamed:@"hstars-4_5.png"];
[self.reviewStars setImage:img];
}
if ([reviewsStarsNumber intValue] == 100) {
UIImage *img = [UIImage imageNamed:@"hstars-5_0.png"];
[self.reviewStars setImage:img];
}