1 Preface
During this time, I learned the basic things of iOS, and the theory needs to be related to the actual situation. I do not want to look for several open-source project codes for research. I am suffering from technical limitations, at the beginning, we can only research and write simple controls. Today we will learn a simple control application, star rating control.
2. Details
This is a very simple control, but not a lot of it is used, so it is good as an entry-level learning material.
Directory structure:
Code Overview:
Ratingcontrollerviewcontroller. h
#import <UIKit/UIKit.h>#import "ZYRatingView.h"@interface ZYViewController : UIViewController<RatingViewDelegate>{ZYRatingView *starView;UILabel *ratingLabel;}@property (nonatomic, retain) IBOutlet ZYRatingView *starView;@property (nonatomic, retain) IBOutlet UILabel *ratingLabel;-(IBAction)clearRating:(id)sender;-(void)ratingChanged:(float)newRating;@end
Ratingcontrollerviewcontroller. m
-(Void) viewdidload {[Super viewdidload]; nslog (@ "Initializing rating View"); // initialize the rating view. The proxy is viewcontroller [starview setimagesdeselected: @ "0.png" partlyselected: @ "1.png" fullselected: @" 2.png" anddelegate: Self]; // set the score [starview displayrating: 1.5];} // clear the score-(ibaction) clearrating :( ID) sender {[starview displayrating: 0.0];} // implement proxy method-(void) ratingchanged :( float) newrating {// display ratinglabel. TEXT = [nsstring stringwithformat: @ "rating is: % 1.1f", newrating];}
If you want to view the complete code, click the link at the end of the article to download the code, which comes with your own comprehensive Chinese comments for your convenience.
Running result:
Click the score control.
Click Clear.
3 conclusion
The above is all content and I hope it will help you.
Demo: http://download.csdn.net/detail/u010013695/5428683