您的位置:首页 > 其它

类似京东淘宝的五星评级,需要的看一下,找找思路

2015-11-13 10:08 459 查看
类似京东淘宝的五星评级,需要的看一下,找找思路

- (void)viewDidLoad {

[super viewDidLoad];

// Do any additional setup after loading the view, typically from a nib.

[self setButton];

}

-(void)setButton

{

buttonArray=[[NSMutableArray alloc]init];//一个全局变量  自行设置

for (NSInteger i=0; i<5; i++) {
UIButton *star=[[UIButton alloc]initWithFrame:CGRectMake(52*i, 100, 50, 50)];
star.tag=i;
star.backgroundColor=[UIColor whiteColor];
star.clipsToBounds=YES;

//大家用的时候删掉下面三行   换成设置默认图片(未选定状态的)
star.layer.cornerRadius=star.frame.size.width/2;
star.layer.borderColor=[UIColor redColor].CGColor;
star.layer.borderWidth=1;

[star addTarget:self action:@selector(starClicked:) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:star];
[buttonArray addObject:star];
}


}

-(void)starClicked:(UIButton *)sender

{

//我们只是 设置了背景色,可以换成是梗概背景图片>>>[button setBackgroundImage:<#(UIImage *)#> forState:<#(UIControlState)#>];

for (NSInteger i=0; i<=sender.tag; i++) {
[(UIButton*)buttonArray[i] setBackgroundColor:[UIColor redColor]];
}
for (NSInteger j=4; j>sender.tag; j--) {
[(UIButton*)buttonArray[j] setBackgroundColor:[UIColor whiteColor]];
}


}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: