支持pod导入 pod 'HCSStarRatingView'
用OC写的简单的评分界面。HCSStarRatingView是一个UIControl子类,可以轻松为用户提供基础的评分界面。
由于使用了PaintCode,它支持所有设备的分辨率,并且加载分数的星星时无需图片。
测试环境:Xcode 6.2,iOS 6.0以上
1、加入代理HCSStarRatingViewDelegate
2、使用
HCSStarRatingView *starRatingView = [[HCSStarRatingView alloc] initWithFrame:self.starView.bounds];
starRatingView.allowsHalfStars = YES;
starRatingView.maximumValue = 5;
starRatingView.minimumValue = 0;
starRatingView.value = 0;
starRatingView.tintColor = [UIColor colorWithRed:232/255.0 green:156/255.0 blue:39/255.0 alpha:1.0];
// starRatingView.userInteractionEnabled = NO;
[starRatingView addTarget:self action:@selector(starRatingViewdidChangeValue:) forControlEvents:UIControlEventValueChanged];
[self.view addSubview:starRatingView];
//还可以使用图片
starRatingView.emptyStarImage = [UIImage imageNamed:@"heart-empty"];
starRatingView.halfStarImage = [UIImage imageNamed:@"heart-half"]; // optional
starRatingView.filledStarImage = [UIImage imageNamed:@"heart-full"];
3、实现代理HCSStarRatingViewDelegate
- (void) starRatingViewdidChangeValue:(HCSStarRatingView *)sender {
NSLog(@"Changed rating to %f", sender.value);
}