我一直在寻找一个五星评级控制一段时间,并没有找到一个可靠的解决方案。 这个问题:
Anyone know whether there is a 5-star rating component on iPhone?
提供了几个不再可用的项目链接,但我无法追踪它们。
编辑:我显然不善于追踪项目,但我认为我的部分问题仍然存在。这是更新后的链接http://code.google.com/p/s7ratingview/downloads/detail?name=s7ratingview-basic-release.zip
所以这个问题是2部分 - 那里有一个可靠的预制解决方案,你可以指导我吗?
是否更好/相当容易(是的,我意识到这两个方面存在冲突)成长我自己的解决方案?你能给我一些提示/资源吗?我理解子类化UIView和跟踪触摸事件的基本思想,将另一个图像的顶部图像展开为看起来像星星,但更多的方向会有所帮助。我已经在iphone上开发了一个星期不到一个星期,仍然需要一点手握。
答案 0 :(得分:9)
您可以尝试DYRateView。我想尽可能多地重用Ray教程中的那个,但是它缺少一些功能,所以我自己做了一个。
您可以查看我的博客,了解有关如何在项目中使用DYRateView的更多详细信息:http://iappexperience.com/post/23227218867/dyrateview-a-simple-yet-powerful-rating-control-for。
picture http://f.cl.ly/items/2D2R152W1z3T0O033f0G/DYRateView---readonly.png
picture http://f.cl.ly/items/1d291U2w423y3t2L0B02/DYRateView---editable.png
答案 1 :(得分:8)
答案 2 :(得分:1)
您可以尝试DLStarRating的另一种方法,让您自定义星星下方的区域,检测触摸。
答案 3 :(得分:0)
轻松获得明星遵循此准则并复制并粘贴到您的项目中并轻松运行。
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
startview = [[UIView alloc] initWithFrame:CGRectMake(45, 70, 230, 50)];
startview.backgroundColor = [UIColor redColor];
NSInteger getrating = 0;
int x = 5;
for (int k = 1; k <= 5; k++)
{
UIImageView * mystarimage = [[UIImageView alloc] initWithFrame:CGRectMake(x, 5, 40, 40)];
if (getrating >= k)
{
mystarimage.image = [UIImage imageNamed:@"star.png"];
}
else
{
mystarimage.image = [UIImage imageNamed:@"gray-star.png"];
}
mystarimage.tag = k;
mystarimage.userInteractionEnabled = YES;
[startview addSubview:mystarimage];
UITapGestureRecognizer *letterTapRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(updateStar:)];
rateMember = mystarimage.tag;
NSLog(@"rateing %ld",(long)rateMember);
letterTapRecognizer.numberOfTapsRequired = 1;
[mystarimage addGestureRecognizer:letterTapRecognizer];
x = x + 45;
}
[self.view addSubview:startview];
}
-(void)updateStar :(UITapGestureRecognizer*)sender
{
UIView *view = sender.view;
NSLog(@"hello ji %ld", (long)view.tag);
NSInteger getrating;
switch (view.tag)
{
case 1:
NSLog(@"press 1");
rateMember = 1;
break;
case 2:
NSLog(@"press 2");
rateMember = 2;
break;
case 3:
NSLog(@"press 3");
rateMember = 3;
break;
case 4:
NSLog(@"press 4");
rateMember = 4;
break;
case 5:
NSLog(@"press 4");
rateMember = 5;
break;
default:
NSLog(@"press 5");
rateMember = 5;
break;
}
getrating = rateMember;
NSLog(@"Get rating -------> %ld",(long)getrating);
int x = 5;
for (int k = 1; k <= 5 ; k++)
{
UIImageView * mystarimage = [[UIImageView alloc] initWithFrame:CGRectMake(x, 5, 40, 40)];
if (getrating >= k)
{
mystarimage.image = [UIImage imageNamed:@"star.png"];
}
else
{
mystarimage.image = [UIImage imageNamed:@"gray-star.png"];
}
mystarimage.tag = k;
mystarimage.userInteractionEnabled = YES;
[startview addSubview:mystarimage];
UITapGestureRecognizer *letterTapRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(updateStar:)];
letterTapRecognizer.numberOfTapsRequired = 1;
[mystarimage addGestureRecognizer:letterTapRecognizer];
x = x + 45;
}
}