一,效果图。
二,工程图。
三,代码。
RootViewController.m
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
UIImageView *imageView=[[UIImageView alloc] initWithFrame:CGRectMake(10, 80, 300, 50)];
//获得评分的图片
[imageView setImage:[self setStarImage:@"4"]];
imageView.backgroundColor=[UIColor clearColor];
[self.view addSubview:imageView];
}
//根据分数,反回图片
-(UIImage *)setStarImage:(NSString *)str
{
float a=atof([str UTF8String]);
UIImage * image;
if(a==0.000000){
image=[UIImage imageNamed:@"star0.png"];
}else if(a>0.000000&&a<1.000000){
image=[UIImage imageNamed:@"star1.png"];
}else if(a==1.000000){
image=[UIImage imageNamed:@"star2.png"];
}else if(a>1.000000&&a<2.000000){
image=[UIImage imageNamed:@"star3.png"];
}else if(a==2.000000){
image=[UIImage imageNamed:@"star4.png"];
}else if(a>2.000000&&a<3.000000){
image=[UIImage imageNamed:@"star5.png"];
}else if(a==3.0000000){
image=[UIImage imageNamed:@"star6.png"];
}else if(a>3.000000&&a<4.000000){
image=[UIImage imageNamed:@"star7.png"];
}else if(a==4.000000){
image=[UIImage imageNamed:@"star8.png"];
}else if(a>4.000000&&a<5.000000){
image=[UIImage imageNamed:@"star9.png"];
}else if(a==5.000000){
image=[UIImage imageNamed:@"star10.png"];
}
return image;
}