最近在做的项目中涉及到了用户评分,用到的是类似淘宝的那种五星好评,就是点击第几个星星就亮几颗星星。
我没有用第三方,都是自己写的逻辑算法,因为最近空闲时间太少还没来得及进行封装,也可能是因为太懒了。。。哈哈~~
====上代码===============
NSArray * feelTitArr = @[@"中文服务",@"医院环境",@"治疗满意度"];
for (int i =0; i<3; i++) {
UILabel * feelTitLable = [[UILabel alloc]initWithFrame:CGRectMake(10, 50+50*i, 100, 50)];
feelTitLable . textColor = THREE_COLOR;
feelTitLable . font = [UIFont systemFontOfSize:13];
feelTitLable . text = feelTitArr[i];
[self . view addSubview:feelTitLable];
UIView * lineView = [[UIView alloc]initWithFrame:CGRectMake(0, 50*i+50, SCREEN_WIDTH, 1)];
lineView . backgroundColor = LINE_COLOR;
[self . view addSubview:lineView];
for (int j=0; j<5; j++) {
UIButton * xingBtn = [UIButton buttonWithType:UIButtonTypeCustom];
xingBtn . frame = CGRectMake(SCREEN_WIDTH-140+(20+5)*j, 65+50*i, 20, 20);
[xingBtn setBackgroundImage:[UIImage imageNamed:@"guanzhu1@2x"] forState:UIControlStateNormal];
xingBtn . tag = i*100+j;
[xingBtn addTarget:self action:@selector(xingBtnClick:) forControlEvents:UIControlEventTouchUpInside];
[self . view addSubview:xingBtn];
[xingBtnArr addObject:xingBtn];
}
}
//------->>星星按钮的点击方法
-(void)xingBtnClick:(UIButton*)sender
{
/**
sender . tag/100(取商为第几行) sender . tag%100(取余为第几列)
*/
for (UIButton * button in xingBtnArr) {
if (button . tag%100<=sender.tag%100 && button .tag/100 ==sender.tag/100) {
[button setBackgroundImage:[UIImage imageNamed:@"guanzhu2@2x"] forState:UIControlStateNormal];
}else if (button .tag/100 ==sender.tag/100){
[button setBackgroundImage:[UIImage imageNamed:@"guanzhu1@2x"] forState:UIControlStateNormal];
}
}
//记录用户对不同感受的评价星星数量
if (sender.tag/100==0) {
manYiDu_Num = sender . tag%100;
}else if (sender.tag/100==1){
zhongZhangDu_Num = sender . tag%100;
}else{
baHenDu_Num = sender . tag%100;
}
}
ok 就是这么简单粗暴,我就喜欢这个样子。。。
最后给大家上一张效果图以便可以直观的看到效果知道是否是自己需要的东东!!!!
!!!!!!!!!!!<以大大的叹号结尾!!!>