AMRatingControl是一个UI控件,它类似于在iPod应用程序中看到的“星形评分”控件。
AMRatingControl允许您从0开始选择任何数量的星。
您可以使用默认的星形符号,并自定义颜色或指定自定义图像。
- 使用CocoaPods
pod 'AMRatingControl'
- 不使用CocoaPods
将AMRatingControl.h
和AMRatingControl.m
添加到您的项目中。
#include "AMRatingControl.h"
// Create a simple instance, initing with :
// - a CGPoint (the position in your view from which it will be drawn)
// - and max rating
AMRatingControl *simpleRatingControl = [[AMRatingControl alloc] initWithLocation:(CGPoint)location
andMaxRating:(NSInteger)maxRating];
// Customize the current rating if needed
[ratingControl setRating:(NSInteger)rating];
// 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).
// - and max rating
AMRatingControl *imagesRatingControl = [[AMRatingControl alloc] initWithLocation:(CGPoint)location
emptyImage:(UIImage *)emptyImageOrNil
solidImage:(UIImage *)solidImageOrNil
andMaxRating:(NSInteger)maxRating];
// Create an instance with custom colors, 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).
// - and max rating
AMRatingControl *coloredRatingControl = [[AMRatingControl alloc] initWithLocation:(CGPoint)location
emptyColor:(UIColor *)emptyColorOrNi
solidColor:(UIColor *)solidColorOrNi
andMaxRating:(NSInteger)maxRating];
// Add the control(s) as subview of your view
[view addSubview:simpleRatingControl];
[view addSubview:imagesRatingControl];
[view addSubview:coloredRatingControl];
AMRatingControl使用ARC。
AMRatingControl可在MIT许可协议下使用。有关更多信息,请参阅LICENSE文件。