APP rating (star like) is very simple, app stars

Source: Internet
Author: User

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:

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.