To run the example project, clone the repo, and run pod install
from the Example directory first.
GRStarsView is available through CocoaPods. To install it, simply add the following line to your Podfile:
pod "GRStarsView"
GRStarsView *starsView = [[GRStarsView alloc] initWithStarSize:CGSizeMake(30, 30) margin:10 numberOfStars:5];
初始化了星星的尺寸,间距和个数; 此时starsView的默认origin为(0, 0),size已设置好;
starsView.frame = CGRectMake(50, 100, starsView.frame.size.width, starsView.frame.size.height);
[view addSubview:starsView]; //view为某个视图
starsView.allowSelect = YES; // 默认可点击
starsView.allowDecimal = YES; //默认可显示小数
starsView.allowDragSelect = NO;//默认不可拖动评分,可拖动下需可点击才有效
starsView.touchedActionBlock = ^(CGFloat score) {
infoLabel.text = [NSString stringWithFormat:@" 分数: %.1f", score];
其中,默认返回的score精确到两位。
starsView.score = 4.5;
(若在此之前设置了回调block,会触发一次回调)
Assuner-Lee, [email protected]
GRStarsView is available under the MIT license. See the LICENSE file for more info.