├── .gitignore ├── LICENSE ├── README.md ├── TPFloatRatingView.h ├── TPFloatRatingView.m ├── TPFloatRatingViewDemo.gif └── TPFloatRatingViewDemo ├── TPFloatRatingViewDemo.xcodeproj ├── project.pbxproj ├── project.xcworkspace │ ├── contents.xcworkspacedata │ └── xcshareddata │ │ └── TPFloatRatingViewDemo.xccheckout └── xcuserdata │ └── gren.xcuserdatad │ └── xcschemes │ ├── TPFloatRatingViewDemo.xcscheme │ └── xcschememanagement.plist └── TPFloatRatingViewDemo ├── Base.lproj └── Main.storyboard ├── Images.xcassets ├── AppIcon.appiconset │ └── Contents.json ├── LaunchImage.launchimage │ └── Contents.json ├── StarEmpty.imageset │ ├── Contents.json │ └── StarEmpty@2x.png └── StarFull.imageset │ ├── Contents.json │ └── StarFull@2x.png ├── TPAppDelegate.h ├── TPAppDelegate.m ├── TPFloatRatingViewDemo-Info.plist ├── TPFloatRatingViewDemo-Prefix.pch ├── TPViewController.h ├── TPViewController.m ├── en.lproj └── InfoPlist.strings └── main.m /.gitignore: -------------------------------------------------------------------------------- 1 | *.xcuserstate -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2014 Glen Yi 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | TPFloatRatingView 2 | ================= 3 | 4 | A simple rating view with whole, half or floating point values. I couldn't find anything that easily set floating point ratings, so I made this control based on the Ray Wenderlich tutorial found [here](http://goo.gl/B49Al4). Some of the best iOS tutorials that I've come across. 5 | 6 | ![TPFloatRatingView Demo](https://raw.github.com/strekfus/TPFloatRatingView/master/TPFloatRatingViewDemo.gif "TPFloatRatingView Demo") 7 | 8 | Usage 9 | ----- 10 | 11 | Initialize from a nib/xib or programmatically. Set the empty and full image, then you're pretty much good to go! Check out the demo app to see how it can be used. 12 | 13 | How it works 14 | ------------ 15 | 16 | The concept is a little different from the source tutorial. The float rating view lays the full image views on top of the empty image views then sets the CALayer mask property to hide the full images. The full image view mask frame is calculated on the fly to make everything work. 17 | -------------------------------------------------------------------------------- /TPFloatRatingView.h: -------------------------------------------------------------------------------- 1 | // 2 | // TPFloatRatingView.h 3 | // TPFloatRatingViewApp 4 | // 5 | // Created by Glen Yi on 2/26/2014. 6 | // Copyright (c) 2014 Glen Yi. All rights reserved. 7 | // 8 | // Version 1.0 9 | 10 | #import 11 | 12 | @protocol TPFloatRatingViewDelegate; 13 | 14 | /** 15 | A simple rating view that can set whole, half or floating point ratings. 16 | */ 17 | @interface TPFloatRatingView : UIView 18 | 19 | @property (weak, nonatomic) id delegate; 20 | 21 | /** 22 | Sets the empty image (e.g. a star outline) 23 | */ 24 | @property (strong, nonatomic) UIImage *emptySelectedImage; 25 | 26 | /** 27 | Sets the full image that is overlayed on top of the empty image. 28 | Should be same size and shape as the empty image. 29 | */ 30 | @property (strong, nonatomic) UIImage *fullSelectedImage; 31 | 32 | /** 33 | Sets the empty and full image view content mode. Defaults to UIViewContentModeCenter. 34 | */ 35 | @property (nonatomic) UIViewContentMode contentMode; 36 | 37 | /** 38 | Minimum rating. Default is 0. 39 | */ 40 | @property (nonatomic) NSInteger minRating; 41 | 42 | /** 43 | Max rating value. Default is 5. 44 | */ 45 | @property (nonatomic) NSInteger maxRating; 46 | 47 | /** 48 | Minimum image size. Default is CGSize(5,5). 49 | */ 50 | @property (nonatomic) CGSize minImageSize; 51 | 52 | /** 53 | Set the current rating. Default is 0. 54 | */ 55 | @property (nonatomic) CGFloat rating; 56 | 57 | /** 58 | Sets whether or not the rating view is editable. Default is NO. 59 | */ 60 | @property (nonatomic) BOOL editable; 61 | 62 | /** 63 | Ratings change by 0.5. Overrides floatRatings property. Default is NO. 64 | */ 65 | @property (nonatomic) BOOL halfRatings; 66 | 67 | /** 68 | Ratings change by floating point values. Default is NO. 69 | */ 70 | @property (nonatomic) BOOL floatRatings; 71 | 72 | @end 73 | 74 | 75 | @protocol TPFloatRatingViewDelegate 76 | @optional 77 | /** 78 | Returns the rating value when touch events end. 79 | */ 80 | - (void)floatRatingView:(TPFloatRatingView *)ratingView ratingDidChange:(CGFloat)rating; 81 | 82 | /** 83 | Returns the rating value as the user pans. 84 | */ 85 | - (void)floatRatingView:(TPFloatRatingView *)ratingView continuousRating:(CGFloat)rating; 86 | @end -------------------------------------------------------------------------------- /TPFloatRatingView.m: -------------------------------------------------------------------------------- 1 | // 2 | // TPFloatRatingView.m 3 | // TPFloatRatingViewApp 4 | // 5 | // Created by Glen Yi on 2/26/2014. 6 | // Copyright (c) 2014 Glen Yi. All rights reserved. 7 | // 8 | 9 | #import "TPFloatRatingView.h" 10 | 11 | @interface TPFloatRatingView() 12 | 13 | @property (strong, nonatomic) NSMutableArray *emptyImageViews; 14 | @property (strong, nonatomic) NSMutableArray *fullImageViews; 15 | 16 | @end 17 | 18 | @implementation TPFloatRatingView 19 | 20 | - (void)baseInit 21 | { 22 | _emptySelectedImage = nil; 23 | _fullSelectedImage = nil; 24 | _contentMode = UIViewContentModeCenter; 25 | _minRating = 0; 26 | _maxRating = 5; 27 | _minImageSize = CGSizeMake(5, 5); 28 | _rating = 0; 29 | _editable = NO; 30 | _halfRatings = NO; 31 | _floatRatings = NO; 32 | _delegate = nil; 33 | 34 | _emptyImageViews = [[NSMutableArray alloc] init]; 35 | _fullImageViews = [[NSMutableArray alloc] init]; 36 | [self initImageViews]; 37 | } 38 | 39 | - (id)initWithFrame:(CGRect)frame 40 | { 41 | self = [super initWithFrame:frame]; 42 | if (self) { 43 | [self baseInit]; 44 | } 45 | return self; 46 | } 47 | 48 | - (id)initWithCoder:(NSCoder *)aDecoder 49 | { 50 | if ((self = [super initWithCoder:aDecoder])) { 51 | [self baseInit]; 52 | } 53 | return self; 54 | } 55 | 56 | - (void)refresh 57 | { 58 | for (int i = 0; i < self.fullImageViews.count; ++i) { 59 | UIImageView *imageView = [self.fullImageViews objectAtIndex:i]; 60 | 61 | // Change rating display by updating Full selected image layer mask 62 | if (self.rating >= i+1) { 63 | imageView.layer.mask = nil; 64 | imageView.hidden = NO; 65 | } 66 | else if (self.rating>i && self.rating= 0; i--) { 211 | UIImageView *imageView = [self.emptyImageViews objectAtIndex:i]; 212 | if (touchLocation.x > imageView.frame.origin.x) { 213 | // Find touch point in image view 214 | CGPoint newLocation = [imageView convertPoint:touchLocation fromView:self]; 215 | if ([imageView pointInside:newLocation withEvent:nil] && (self.floatRatings || self.halfRatings)) { 216 | CGFloat decimalNum = newLocation.x/imageView.frame.size.width; 217 | newRating = i + decimalNum; 218 | if (self.halfRatings) { 219 | newRating = i + (decimalNum>0.75? 1:(decimalNum>0.25? 0.5:0)); 220 | } 221 | } 222 | else { 223 | newRating = i+1; 224 | } 225 | break; 226 | } 227 | } 228 | 229 | self.rating = newRating 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /TPFloatRatingViewDemo/TPFloatRatingViewDemo.xcodeproj/project.xcworkspace/xcshareddata/TPFloatRatingViewDemo.xccheckout: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IDESourceControlProjectFavoriteDictionaryKey 6 | 7 | IDESourceControlProjectIdentifier 8 | 3752CD4D-F380-4DAF-A8C2-DE71FFA72961 9 | IDESourceControlProjectName 10 | TPFloatRatingViewDemo 11 | IDESourceControlProjectOriginsDictionary 12 | 13 | AE10BD97C0DF8C377D6D706AB483DF35437CF391 14 | https://github.com/strekfus/TPFloatRatingView.git 15 | 16 | IDESourceControlProjectPath 17 | TPFloatRatingViewDemo/TPFloatRatingViewDemo.xcodeproj/project.xcworkspace 18 | IDESourceControlProjectRelativeInstallPathDictionary 19 | 20 | AE10BD97C0DF8C377D6D706AB483DF35437CF391 21 | ../../.. 22 | 23 | IDESourceControlProjectURL 24 | https://github.com/strekfus/TPFloatRatingView.git 25 | IDESourceControlProjectVersion 26 | 111 27 | IDESourceControlProjectWCCIdentifier 28 | AE10BD97C0DF8C377D6D706AB483DF35437CF391 29 | IDESourceControlProjectWCConfigurations 30 | 31 | 32 | IDESourceControlRepositoryExtensionIdentifierKey 33 | public.vcs.git 34 | IDESourceControlWCCIdentifierKey 35 | AE10BD97C0DF8C377D6D706AB483DF35437CF391 36 | IDESourceControlWCCName 37 | TPFloatRatingView 38 | 39 | 40 | 41 | 42 | -------------------------------------------------------------------------------- /TPFloatRatingViewDemo/TPFloatRatingViewDemo.xcodeproj/xcuserdata/gren.xcuserdatad/xcschemes/TPFloatRatingViewDemo.xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 9 | 15 | 21 | 22 | 23 | 24 | 25 | 30 | 31 | 33 | 39 | 40 | 41 | 42 | 43 | 49 | 50 | 51 | 52 | 61 | 62 | 68 | 69 | 70 | 71 | 72 | 73 | 79 | 80 | 86 | 87 | 88 | 89 | 91 | 92 | 95 | 96 | 97 | -------------------------------------------------------------------------------- /TPFloatRatingViewDemo/TPFloatRatingViewDemo.xcodeproj/xcuserdata/gren.xcuserdatad/xcschemes/xcschememanagement.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | SchemeUserState 6 | 7 | TPFloatRatingViewDemo.xcscheme 8 | 9 | orderHint 10 | 0 11 | 12 | 13 | SuppressBuildableAutocreation 14 | 15 | B25B077F18BF954400AFA378 16 | 17 | primary 18 | 19 | 20 | B25B07A018BF954400AFA378 21 | 22 | primary 23 | 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /TPFloatRatingViewDemo/TPFloatRatingViewDemo/Base.lproj/Main.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 27 | 33 | 39 | 45 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | -------------------------------------------------------------------------------- /TPFloatRatingViewDemo/TPFloatRatingViewDemo/Images.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "iphone", 5 | "size" : "29x29", 6 | "scale" : "2x" 7 | }, 8 | { 9 | "idiom" : "iphone", 10 | "size" : "40x40", 11 | "scale" : "2x" 12 | }, 13 | { 14 | "idiom" : "iphone", 15 | "size" : "60x60", 16 | "scale" : "2x" 17 | } 18 | ], 19 | "info" : { 20 | "version" : 1, 21 | "author" : "xcode" 22 | } 23 | } -------------------------------------------------------------------------------- /TPFloatRatingViewDemo/TPFloatRatingViewDemo/Images.xcassets/LaunchImage.launchimage/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "orientation" : "portrait", 5 | "idiom" : "iphone", 6 | "extent" : "full-screen", 7 | "minimum-system-version" : "7.0", 8 | "scale" : "2x" 9 | }, 10 | { 11 | "orientation" : "portrait", 12 | "idiom" : "iphone", 13 | "subtype" : "retina4", 14 | "extent" : "full-screen", 15 | "minimum-system-version" : "7.0", 16 | "scale" : "2x" 17 | } 18 | ], 19 | "info" : { 20 | "version" : 1, 21 | "author" : "xcode" 22 | } 23 | } -------------------------------------------------------------------------------- /TPFloatRatingViewDemo/TPFloatRatingViewDemo/Images.xcassets/StarEmpty.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "universal", 5 | "scale" : "1x" 6 | }, 7 | { 8 | "idiom" : "universal", 9 | "scale" : "2x", 10 | "filename" : "StarEmpty@2x.png" 11 | } 12 | ], 13 | "info" : { 14 | "version" : 1, 15 | "author" : "xcode" 16 | } 17 | } -------------------------------------------------------------------------------- /TPFloatRatingViewDemo/TPFloatRatingViewDemo/Images.xcassets/StarEmpty.imageset/StarEmpty@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/glenyi/TPFloatRatingView/bfd536e01e19328fabf95e5c97539bf4b1a510b0/TPFloatRatingViewDemo/TPFloatRatingViewDemo/Images.xcassets/StarEmpty.imageset/StarEmpty@2x.png -------------------------------------------------------------------------------- /TPFloatRatingViewDemo/TPFloatRatingViewDemo/Images.xcassets/StarFull.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "universal", 5 | "scale" : "1x" 6 | }, 7 | { 8 | "idiom" : "universal", 9 | "scale" : "2x", 10 | "filename" : "StarFull@2x.png" 11 | } 12 | ], 13 | "info" : { 14 | "version" : 1, 15 | "author" : "xcode" 16 | } 17 | } -------------------------------------------------------------------------------- /TPFloatRatingViewDemo/TPFloatRatingViewDemo/Images.xcassets/StarFull.imageset/StarFull@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/glenyi/TPFloatRatingView/bfd536e01e19328fabf95e5c97539bf4b1a510b0/TPFloatRatingViewDemo/TPFloatRatingViewDemo/Images.xcassets/StarFull.imageset/StarFull@2x.png -------------------------------------------------------------------------------- /TPFloatRatingViewDemo/TPFloatRatingViewDemo/TPAppDelegate.h: -------------------------------------------------------------------------------- 1 | // 2 | // TPAppDelegate.h 3 | // TPFloatRatingViewDemo 4 | // 5 | // Created by Glen Yi on 2/27/2014. 6 | // Copyright (c) 2014 Glen. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface TPAppDelegate : UIResponder 12 | 13 | @property (strong, nonatomic) UIWindow *window; 14 | 15 | @end 16 | -------------------------------------------------------------------------------- /TPFloatRatingViewDemo/TPFloatRatingViewDemo/TPAppDelegate.m: -------------------------------------------------------------------------------- 1 | // 2 | // TPAppDelegate.m 3 | // TPFloatRatingViewDemo 4 | // 5 | // Created by Glen Yi on 2/27/2014. 6 | // Copyright (c) 2014 Glen. All rights reserved. 7 | // 8 | 9 | #import "TPAppDelegate.h" 10 | 11 | @implementation TPAppDelegate 12 | 13 | - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 14 | { 15 | // Override point for customization after application launch. 16 | return YES; 17 | } 18 | 19 | - (void)applicationWillResignActive:(UIApplication *)application 20 | { 21 | // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state. 22 | // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game. 23 | } 24 | 25 | - (void)applicationDidEnterBackground:(UIApplication *)application 26 | { 27 | // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. 28 | // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. 29 | } 30 | 31 | - (void)applicationWillEnterForeground:(UIApplication *)application 32 | { 33 | // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background. 34 | } 35 | 36 | - (void)applicationDidBecomeActive:(UIApplication *)application 37 | { 38 | // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface. 39 | } 40 | 41 | - (void)applicationWillTerminate:(UIApplication *)application 42 | { 43 | // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. 44 | } 45 | 46 | @end 47 | -------------------------------------------------------------------------------- /TPFloatRatingViewDemo/TPFloatRatingViewDemo/TPFloatRatingViewDemo-Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleDisplayName 8 | ${PRODUCT_NAME} 9 | CFBundleExecutable 10 | ${EXECUTABLE_NAME} 11 | CFBundleIdentifier 12 | com.onthepursuit.${PRODUCT_NAME:rfc1034identifier} 13 | CFBundleInfoDictionaryVersion 14 | 6.0 15 | CFBundleName 16 | ${PRODUCT_NAME} 17 | CFBundlePackageType 18 | APPL 19 | CFBundleShortVersionString 20 | 1.0 21 | CFBundleSignature 22 | ???? 23 | CFBundleVersion 24 | 1.0 25 | LSRequiresIPhoneOS 26 | 27 | UIMainStoryboardFile 28 | Main 29 | UIRequiredDeviceCapabilities 30 | 31 | armv7 32 | 33 | UISupportedInterfaceOrientations 34 | 35 | UIInterfaceOrientationPortrait 36 | 37 | 38 | 39 | -------------------------------------------------------------------------------- /TPFloatRatingViewDemo/TPFloatRatingViewDemo/TPFloatRatingViewDemo-Prefix.pch: -------------------------------------------------------------------------------- 1 | // 2 | // Prefix header 3 | // 4 | // The contents of this file are implicitly included at the beginning of every source file. 5 | // 6 | 7 | #import 8 | 9 | #ifndef __IPHONE_5_0 10 | #warning "This project uses features only available in iOS SDK 5.0 and later." 11 | #endif 12 | 13 | #ifdef __OBJC__ 14 | #import 15 | #import 16 | #endif 17 | -------------------------------------------------------------------------------- /TPFloatRatingViewDemo/TPFloatRatingViewDemo/TPViewController.h: -------------------------------------------------------------------------------- 1 | // 2 | // TPViewController.h 3 | // TPFloatRatingViewDemo 4 | // 5 | // Created by Glen Yi on 2/27/2014. 6 | // Copyright (c) 2014 Glen. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "TPFloatRatingView.h" 11 | 12 | @interface TPViewController : UIViewController 13 | 14 | @property (strong, nonatomic) IBOutlet UILabel *ratingLabel; 15 | @property (strong, nonatomic) IBOutlet UILabel *liveLabel; 16 | @property (strong, nonatomic) IBOutlet TPFloatRatingView *ratingView; 17 | @property (strong, nonatomic) IBOutlet UISegmentedControl *segmentedControl; 18 | 19 | - (IBAction)controlChange:(id)sender; 20 | 21 | @end 22 | -------------------------------------------------------------------------------- /TPFloatRatingViewDemo/TPFloatRatingViewDemo/TPViewController.m: -------------------------------------------------------------------------------- 1 | // 2 | // TPViewController.m 3 | // TPFloatRatingViewDemo 4 | // 5 | // Created by Glen Yi on 2/27/2014. 6 | // Copyright (c) 2014 Glen. All rights reserved. 7 | // 8 | 9 | #import "TPViewController.h" 10 | 11 | @interface TPViewController () 12 | 13 | @end 14 | 15 | @implementation TPViewController 16 | 17 | - (void)viewDidLoad 18 | { 19 | [super viewDidLoad]; 20 | // Do any additional setup after loading the view, typically from a nib. 21 | 22 | self.ratingView.delegate = self; 23 | self.ratingView.emptySelectedImage = [UIImage imageNamed:@"StarEmpty"]; 24 | self.ratingView.fullSelectedImage = [UIImage imageNamed:@"StarFull"]; 25 | self.ratingView.contentMode = UIViewContentModeScaleAspectFill; 26 | self.ratingView.maxRating = 5; 27 | self.ratingView.minRating = 1; 28 | self.ratingView.rating = 2.5; 29 | self.ratingView.editable = YES; 30 | self.ratingView.halfRatings = YES; 31 | self.ratingView.floatRatings = NO; 32 | 33 | self.ratingLabel.text = [NSString stringWithFormat:@"%.2f", self.ratingView.rating]; 34 | self.liveLabel.text = [NSString stringWithFormat:@"%.2f", self.ratingView.rating]; 35 | 36 | self.segmentedControl.selectedSegmentIndex = 1; 37 | } 38 | 39 | - (void)didReceiveMemoryWarning 40 | { 41 | [super didReceiveMemoryWarning]; 42 | // Dispose of any resources that can be recreated. 43 | } 44 | 45 | #pragma mark - TPFloatRatingViewDelegate 46 | 47 | - (void)floatRatingView:(TPFloatRatingView *)ratingView ratingDidChange:(CGFloat)rating 48 | { 49 | self.ratingLabel.text = [NSString stringWithFormat:@"%.2f", rating]; 50 | } 51 | 52 | - (void)floatRatingView:(TPFloatRatingView *)ratingView continuousRating:(CGFloat)rating 53 | { 54 | self.liveLabel.text = [NSString stringWithFormat:@"%.2f", rating]; 55 | } 56 | 57 | - (IBAction)controlChange:(id)sender 58 | { 59 | UISegmentedControl *control = (UISegmentedControl *)sender; 60 | 61 | self.ratingView.halfRatings = control.selectedSegmentIndex==1? YES:NO; 62 | self.ratingView.floatRatings = control.selectedSegmentIndex==2? YES:NO; 63 | } 64 | 65 | @end 66 | -------------------------------------------------------------------------------- /TPFloatRatingViewDemo/TPFloatRatingViewDemo/en.lproj/InfoPlist.strings: -------------------------------------------------------------------------------- 1 | /* Localized versions of Info.plist keys */ 2 | 3 | -------------------------------------------------------------------------------- /TPFloatRatingViewDemo/TPFloatRatingViewDemo/main.m: -------------------------------------------------------------------------------- 1 | // 2 | // main.m 3 | // TPFloatRatingViewDemo 4 | // 5 | // Created by Glen Yi on 2/27/2014. 6 | // Copyright (c) 2014 Glen. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | #import "TPAppDelegate.h" 12 | 13 | int main(int argc, char * argv[]) 14 | { 15 | @autoreleasepool { 16 | return UIApplicationMain(argc, argv, nil, NSStringFromClass([TPAppDelegate class])); 17 | } 18 | } 19 | --------------------------------------------------------------------------------