StarRating 1.6

StarRating 1.6

TestsTested
LangLanguage Obj-CObjective C
License MIT
ReleasedLast Release Jun 2017

Maintained by 李亚军.



  • By
  • li625317534

StarRating

CI Status Version License Platform

Example

To run the example project, clone the repo, and run pod install from the Example directory first.

说明简介
可以进行打分,或者进行分数展示,这个视图可以打0分
属性说明:
horizontalSpacing: 设置展示的图片(例如星星图片)之间的水平距离
highlightImage , unHightlightImage: 设置得到分数的时候显示的图片(默认彩色星星图片),没有得到分数时候显示的图片(默认灰色星星图片)
aspectRatio: 显示分数图片的高宽比,宽度是与视图的宽度与图片间隙决定的,如果我们用到的宽高比不是1:1,那么需要使用这个参数设置一下,防止图片拉伸
isAllowedSliding: 是否允许滑动打分,如果不允许只能打整数的分数例如:1分,2分,3分...,不能打1.2分等
currentValue: 当前需要展示的分数,如果有5颗星,那么这里的值范围0~5,如果设置为-1,那么为0,如果设置为9那么为5,我们可以关闭用户交互的方法,只让展示设置的分数,而不能够通过点击滑动的方式引起展示的分数发生改变(userInteractionEnabled设置为 NO 关闭交互)
starNum: 星星的个数,这里每一个颗星,代表1分,storyboard 中初始化默认我5颗星
currentValueBlock: 实时展示动态展示当前分数值 

使用方法:
    1: storyboard 中使用
    如果想修改属性,只能在- (void)viewDidLayoutSubviews方法中设置, viewDidLoad 中首次设置无法正常显示例如:
    
        - (void)viewDidLayoutSubviews {
        
            // self.star1 是 StarEvaluatorView 类 
            self.star1.horizontalSpacing = 20;

            // 注意:
               这里不能对星星进行打分,因为这个方法只要视图发生变化,都会执行,并不是仅仅执行一次,如果需要展示分数,并且是动态展示分数, 例如:self.satr1.currentValue = 3,可以在 viewDidLoad 方法中调用设置首次展示的分数值,这里除了 currentValue 属性其他的属性都可以调用
        } 
    2: init 初始化
        StarEvaluatorView *star = [[StarEvaluatorView alloc] initWithFrame:CGRectMake(50, 150, [UIScreen mainScreen].bounds.size.width - 100, 50) withNumberOfStar:4];
        star.currentValueBlock = ^(CGFloat currentValue) {

            dispatch_async(dispatch_get_main_queue(), ^{

                // 这里可以在我们展示分数的 label 上赋值展示
            });
        };
        // 这里不设置默认为0,也就是星星的宽度为视图宽度的1/4
        star.horizontalSpacing = 20;
        star.aspectRatio = 2; // 这里的意思是高度是宽度1.2倍,这里的比例要根据提供的图片决定
        [self.view addSubview:star];

Requirements

Installation

StarRating is available through CocoaPods. To install it, simply add the following line to your Podfile:

pod "StarRating"

Author

li625317534, [email protected]

License

StarRating is available under the MIT license. See the LICENSE file for more info.