iOS-68-星星评价、显示小数点星星评价效果(附demo)

    xiaoxiao2026-01-12  1

    1、上效果图:

    2、 第一个是显示的7.2分的评分 第二个可以点击选择评分

    3、主要代码:

    - (void)creatStarView{ UIImage *gray = [UIImage imageNamed:@"starGrey"]; UIImage *yellow = [UIImage imageNamed:@"strayellow"]; //1.获取星星视图的初始宽高 CGFloat width = gray.size.width *5; CGFloat height = gray.size.height; //2.初始化星星视图 _grayView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, width, height)]; [_grayView setBackgroundColor:[UIColor colorWithPatternImage:gray]]; // 平铺 [self addSubview:_grayView]; _yellowView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, width, height)]; [_yellowView setBackgroundColor:[UIColor colorWithPatternImage:yellow]]; // 平铺 [self addSubview:_yellowView]; //3.放大星星视图与self等高等宽 CGFloat scaleW = self.frame.size.width/width; CGFloat scaleH = self.frame.size.height/height; _grayView.transform = CGAffineTransformMakeScale(scaleW, scaleH); _yellowView.transform = CGAffineTransformMakeScale(scaleW, scaleH); //4.重置星星视图坐标 _grayView.frame = CGRectMake(0, 0, self.frame.size.width, self.frame.size.height); _yellowView.frame = CGRectMake(0, 0, self.frame.size.width, self.frame.size.height); } -(void)setRating:(float)rating{ // _rating = rating; _yellowView.frame = CGRectMake(0, 0, self.frame.size.width *rating/10, self.frame.size.height); }

    demo:http://download.csdn.net/detail/iot_li/9603992

    转载请注明原文地址: https://ju.6miu.com/read-1305915.html
    最新回复(0)