APP rating (star like) is very simple, app stars
1. Use code or storyboard to create five buttons (usually five stars)
I use storyboard.
Remember to set the tag value of the button.
In. h
@ Property (weak, nonatomic) IBOutlet UIButton * btn5;
-(IBAction) btn :( id) sender;
@ Property (weak, nonatomic) IBOutlet UIButton * btn4;
@ Property (weak, nonatomic) IBOutlet UIButton * btn3;
@ Property (weak, nonatomic) IBOutlet UIButton * btn2;
@ Property (weak, nonatomic) IBOutlet UIButton * btn1;
Then in. m
@ Interface ViewController ()
{
NSArray * starArray;
}
@ End
@ Implementation ViewController
-(Void) viewDidLoad {
[Super viewDidLoad];
StarArray = [NSArray arrayWithObjects: _ btn1, _ btn2, _ btn3, _ btn4, _ btn5, nil];
}
-(Void) didReceiveMemoryWarning {
[Super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
-(IBAction) btn :( id) sender
{
UIButton * allBtn = sender;
For (UIButton * button in starArray)
{
If (button. tag <= allBtn. tag)
{
[Button setBackgroundImage: [UIImage imageNamed: @ "goldstar1"] forState: UIControlStateNormal];
// Goldstar1 and greystar2 image names
}
Else
{
[Button setBackgroundImage: [UIImage imageNamed: @ "greystar2"] forState: UIControlStateNormal];
}
}
}
So OK.
The effect is as follows: