StarRatingControl是一个类似于iPod应用程序中看到的“星级评分”的UI控件。
StarRatingControl允许您从0星开始选择任何数量的星。
您可以使用默认的星形符号,并自定义颜色或指定自定义图片。
将StarRatingControl.h
和StarRatingControl.m
添加到您的项目中。
#import "StarRatingControl.h"
// Create a simple instance, initing with :
// - a CGPoint (the position in your view from which it will be drawn)
// - and max rating
StarRatingControl *simpleRatingControl = [[StarRatingControl alloc] initWithLocation:CGPointMake(90, 50)
andMaxRating:5];
// Customize the current rating if needed
[simpleRatingControl setRating:3];
[simpleRatingControl setStarSpacing:10];
// Define block to handle events
simpleRatingControl.editingChangedBlock = ^(NSUInteger rating)
{
[label setText:[NSString stringWithFormat:@"%d", rating]];
};
simpleRatingControl.editingDidEndBlock = ^(NSUInteger rating)
{
[endLabel setText:[NSString stringWithFormat:@"%d", rating]];
};
// Create an instance with images, initing with :
// - a CGPoint (the position in your view from which it will be drawn)
// - a custom empty image and solid image if you wish (pass nil if you want to use the default).
// - initial rating (how many stars the rating will have initially when displayed)
// - and max rating
// This control, when initialized with (at least) the fullStar image will support partial rating stars, i.e., 3.5
UIImage *emptyStar, *fullStar;
emptyStar = [UIImage imageNamed:@"star_rating_empty.png"];
fullStar = [UIImage imageNamed:@"star_rating_full.png"];
StarRatingControl *imagesRatingControl = [[StarRatingControl alloc] initWithLocation:CGPointMake(110, 250)
emptyImage:emptyStar
solidImage:fullStar
initialRating:3.5
andMaxRating:5];
// Create an instance with custom color, initing with :
// - a CGPoint (the position in your view from which it will be drawn)
// - colors for "empty" and "full" rating stars
// - and max rating
StarRatingControl *coloredRatingControl = [[StarRatingControl alloc] initWithLocation:CGPointMake(110, 370)
emptyColor:[UIColor yellowColor]
solidColor:[UIColor redColor]
andMaxRating:5];
// Add the control(s) as subview of your view
[view addSubview:simpleRatingControl];
[view addSubview:imagesRatingControl];
[view addSubview:coloredRatingControl];
StarRatingControl使用ARC。
StarRatingControl在MIT许可下可用。有关更多信息,请参阅LICENSE文件。