GRStarsView icon indicating copy to clipboard operation
GRStarsView copied to clipboard

一个简单实用的iOS 星星评分view,支持小数,支持点击、拖动评分。

GRStarsView

CI Status Version License Platform

Example

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

Requirements

Installation

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

pod "GRStarsView"

先看效果

使用

1. 初始化一个GRStarsView

GRStarsView *starsView = [[GRStarsView alloc] initWithStarSize:CGSizeMake(30, 30) margin:10 numberOfStars:5];

初始化了星星的尺寸,间距和个数; 此时starsView的默认origin为(0, 0),size已设置好;

*2. 设置frame ,并添加到某一个视图上

starsView.frame = CGRectMake(50, 100, starsView.frame.size.width, starsView.frame.size.height);
[view addSubview:starsView]; //view为某个视图

3. 配置属性(可否点击、拖动评分,是否允许小数显示)

 starsView.allowSelect = YES;  // 默认可点击
 starsView.allowDecimal = YES;  //默认可显示小数
 starsView.allowDragSelect = NO;//默认不可拖动评分,可拖动下需可点击才有效

4. 配置触摸(点击,拖动)结束 score改变后的block回调

starsView.touchedActionBlock = ^(CGFloat score) {
        infoLabel.text = [NSString stringWithFormat:@" 分数: %.1f", score];

其中,默认返回的score精确到两位。

*设置score,可绘出星星评分

starsView.score = 4.5;

(若在此之前设置了回调block,会触发一次回调)

谢谢观看,如有错误,请多指正。

Author

Assuner-Lee, [email protected]

License

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