• 【代码笔记】iOS-评分系统(小星星)


    一,效果图。

     

    二,工程图。

    三,代码。

    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;
    }
    复制代码

     

  • 相关阅读:
    maven
    in 和 or 的效率问题
    mac 安装homobrew 报错解决
    卷积的本质及物理意义
    java 多线程 day18 ThreadPoolExecutor
    打jar包
    科三保佑贴
    【问题解决】-《java.lang.NoClassDefFoundException》
    POS-商户手续费-从生活剖析,通俗易懂
    关于荒废空闲时光的思考
  • 原文地址:https://www.cnblogs.com/yang-guang-girl/p/5484474.html
Copyright © 2020-2023  润新知