diff --git a/EDStarRating.podspec b/EDStarRating.podspec index 30ecde3..80563d6 100644 --- a/EDStarRating.podspec +++ b/EDStarRating.podspec @@ -3,7 +3,7 @@ Pod::Spec.new do |s| s.version = "1.1" s.summary = "A configurable star rating control for OSX and iOS, similar to those found in iTunes and the App Store." s.ios.frameworks = 'CoreGraphics' - s.ios.deployment_target = '4.3' + s.ios.deployment_target = '8.0' s.osx.deployment_target = '10.6' s.description = <<-DESC A configurable star rating control for OSX and iOS, similar to those found in iTunes and the App Store. diff --git a/EDStarRating/EDStarRating.h b/EDStarRating/EDStarRating.h index d23151c..5419938 100755 --- a/EDStarRating/EDStarRating.h +++ b/EDStarRating/EDStarRating.h @@ -54,12 +54,16 @@ typedef UIImage EDImage; @property (nonatomic,strong) EDImage *backgroundImage; @property (nonatomic,strong) EDImage *starHighlightedImage; @property (nonatomic,strong) EDImage *starImage; +@property (nonatomic) NSInteger minRating; @property (nonatomic) NSInteger maxRating; @property (nonatomic) float rating; @property (nonatomic) CGFloat horizontalMargin; @property (nonatomic) BOOL editable; @property (nonatomic) EDStarRatingDisplayMode displayMode; @property (nonatomic) float halfStarThreshold; +#if EDSTAR_IOS +@property (nonatomic) NSInteger starSize; +#endif @property (nonatomic,weak) id delegate; @property (nonatomic,copy) EDStarRatingReturnBlock returnBlock; diff --git a/EDStarRating/EDStarRating.m b/EDStarRating/EDStarRating.m index 7b5ad0e..e57c994 100755 --- a/EDStarRating/EDStarRating.m +++ b/EDStarRating/EDStarRating.m @@ -6,7 +6,9 @@ // Distributed under MIT license #import "EDStarRating.h" - +#if EDSTAR_IOS +#import +#endif #define ED_DEFAULT_HALFSTAR_THRESHOLD 0.6 @@ -18,9 +20,10 @@ @interface EDStarRating() @implementation EDStarRating -@synthesize starImage; -@synthesize starHighlightedImage; +@synthesize starImage = _starImage; +@synthesize starHighlightedImage = _starHighlightedImage; @synthesize rating=_rating; +@synthesize minRating; @synthesize maxRating; @synthesize backgroundImage; @synthesize editable; @@ -28,6 +31,9 @@ @implementation EDStarRating @synthesize horizontalMargin; @synthesize halfStarThreshold; @synthesize displayMode; +#if EDSTAR_IOS +@synthesize starSize=_starSize; +#endif #if EDSTAR_MACOSX @synthesize backgroundColor=_backgroundColor; #endif @@ -39,9 +45,10 @@ @implementation EDStarRating -(void)setDefaultProperties { - maxRating=5.0; - _rating=0.0; - horizontalMargin=10.0; + minRating = 1.0; + maxRating = 5.0; + _rating = 0.0; + horizontalMargin = 10.0; displayMode = EDStarRatingDisplayFull; halfStarThreshold=ED_DEFAULT_HALFSTAR_THRESHOLD; [self setBackgroundColor:[EDColor clearColor]]; @@ -110,11 +117,23 @@ -(void)setDisplayMode:(EDStarRatingDisplayMode)dispMode [self setNeedsDisplay]; } +#if EDSTAR_IOS +-(void)setStarSize:(NSInteger)starSize +{ + _starSize = starSize; + if(_starSize != 0 && self.starImage != nil && self.starHighlightedImage != nil){ + self.starImage = [self resizeImageToSize:CGSizeMake(_starSize, _starSize) withImage:self.starImage]; + self.starHighlightedImage = [self resizeImageToSize:CGSizeMake(_starSize, _starSize) withImage:self.starHighlightedImage]; + } + [self setNeedsDisplay]; +} +#endif + #pragma mark - #pragma mark Drawing -(CGPoint)pointOfStarAtPosition:(NSInteger)position highlighted:(BOOL)hightlighted { - CGSize size = hightlighted?starHighlightedImage.size:starImage.size; + CGSize size = hightlighted?_starHighlightedImage.size:_starImage.size; NSInteger starsSpace = self.bounds.size.width - 2*horizontalMargin; @@ -220,7 +239,7 @@ -(void)drawRect:(CGRect)rect } // Draw rating Images - CGSize starSize = starHighlightedImage.size; + CGSize starSize = _starHighlightedImage.size; for( NSInteger i=0 ; i heightFactor) + { + thumbnailPoint.x = (targetWidth - scaledWidth) * 0.5; + } + } + + UIGraphicsBeginImageContext(targetSize); + CGRect thumbnailRect = CGRectZero; + thumbnailRect.origin = thumbnailPoint; + thumbnailRect.size.width = scaledWidth; + thumbnailRect.size.height = scaledHeight; + + [sourceImage drawInRect:thumbnailRect]; + newImage = UIGraphicsGetImageFromCurrentImageContext(); + UIGraphicsEndImageContext(); + + if(newImage == nil) + NSLog(@"Could not scale image"); + + return newImage ; +} +#endif + @end diff --git a/README.md b/README.md index 9d7326d..61c2437 100644 --- a/README.md +++ b/README.md @@ -1,20 +1,20 @@ EDStarRating ![Version Badge](https://go-shields.herokuapp.com/license-BSD-blue.png) =============== -A configurable star rating control for OSX and iOS, similar to those found in iTunes and the App Store. +A configurable star rating control for OSX and iOS, similar to those found in iTunes and the App Store. Fork of https://github.com/erndev/EDStarRating including support for resizing large star images on iOS. Additionally I have rewritten the iOS sample project with the additional presentation of the resizing code. [![Badge w/ Version](https://cocoapod-badges.herokuapp.com/v/EDStarRating/badge.png)](https://cocoadocs.org/docsets/EDStarRating) [![Badge w/ Platform](https://cocoapod-badges.herokuapp.com/p/EDStarRating/badge.svg)](https://cocoadocs.org/docsets/EDStarRating) ###Installation -The easiest way to install EDStarRating is via [CocoaPods](http://cocoapods.org). Add this line to your Podfile: +The easiest way to install this fork of EDStarRating is via [CocoaPods](http://cocoapods.org). Add this line to your Podfile: ```ruby -pod 'EDStarRating' +pod 'EDStarRating', :git => 'https://github.com/martinpfannemueller/EDStarRating.git' ``` -and run `pod install`. +and run `pod install`. You can also install it manually by copying these two files to your project: EDStarRating.h and EDStarRating.m @@ -24,10 +24,11 @@ You can also install it manually by copying these two files to your project: EDS Example: -``` +```objective-c starRating.starImage = [NSImage imageNamed:@"star.png"]; starRating.starHighlightedImage = [NSImage imageNamed:@"starhighlighted.png"]; + starRating.minRating = 1.0; // Prevents ratings below a minimum starRating.maxRating = 5.0; starRating.delegate = self; starRating.horizontalMargin = 12; @@ -37,6 +38,9 @@ Example: starRating.rating= 2.5; + // Resizing of large star image by setting starSize property + starRating.starSize = 20; + ``` ### tintColor support in iOS 7 If you pass to the control a template UIImage (created using rendering mode (UIImageRenderingModeAlwaysTemplate), EDStarRating will tint that image using the control's tintColor property. @@ -45,12 +49,12 @@ If you pass to the control a template UIImage (created using rendering mode (UII ### Compatiblity This control should work in ARC and not ARC projects. On OS X 10.6+ and iOS 4.x+. But it's only tested it with ARC enabled in 10.8+ and iOS 6.0+. Let me now if it works fine for you in other environments. - + ### Screenshots ![EDStarRating](https://github.com/erndev/EDStarRating/raw/master/edstarrating.png) -![EDStarRating](https://github.com/erndev/EDStarRating/raw/master/edstarrating-ios.png) +![EDStarRating](https://raw.githubusercontent.com/martinpfannemueller/EDStarRating/master/edstarrating-ios.png) ### License BSD License. @@ -80,5 +84,5 @@ ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ### Star icons -The star icons and backgrounds used in the sample have been created by [Dan Deming-Henes +The star icons and backgrounds taken from the original project used in the sample have been created by [Dan Deming-Henes ](http://strandeddesign.com). diff --git a/SampleiOS/SampleiOS.xcodeproj/project.pbxproj b/SampleiOS/SampleiOS.xcodeproj/project.pbxproj index c53ce3b..768020f 100644 --- a/SampleiOS/SampleiOS.xcodeproj/project.pbxproj +++ b/SampleiOS/SampleiOS.xcodeproj/project.pbxproj @@ -8,14 +8,17 @@ /* Begin PBXBuildFile section */ 01C5BF7A17A3F04800B7B0BC /* Default-568h@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = 01C5BF7917A3F04800B7B0BC /* Default-568h@2x.png */; }; + 5BBC25321824FCEF00B5B592 /* QuartzCore.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 5BBC25311824FCEF00B5B592 /* QuartzCore.framework */; }; + 5BD3083F1C381D640003AB55 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 5BD3083E1C381D640003AB55 /* Main.storyboard */; }; + 5BD308421C381D8F0003AB55 /* SampleViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 5BD308411C381D8F0003AB55 /* SampleViewController.m */; }; + 5BD308451C3847C00003AB55 /* StarLargeEmpty.png in Resources */ = {isa = PBXBuildFile; fileRef = 5BD308431C3847C00003AB55 /* StarLargeEmpty.png */; }; + 5BD308461C3847C00003AB55 /* StarLarge.png in Resources */ = {isa = PBXBuildFile; fileRef = 5BD308441C3847C00003AB55 /* StarLarge.png */; }; 94B6315B15E4E53F00C7F229 /* UIKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 94B6315A15E4E53F00C7F229 /* UIKit.framework */; }; 94B6315D15E4E53F00C7F229 /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 94B6315C15E4E53F00C7F229 /* Foundation.framework */; }; 94B6315F15E4E53F00C7F229 /* CoreGraphics.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 94B6315E15E4E53F00C7F229 /* CoreGraphics.framework */; }; 94B6316515E4E53F00C7F229 /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = 94B6316315E4E53F00C7F229 /* InfoPlist.strings */; }; 94B6316715E4E53F00C7F229 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 94B6316615E4E53F00C7F229 /* main.m */; }; 94B6316B15E4E53F00C7F229 /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 94B6316A15E4E53F00C7F229 /* AppDelegate.m */; }; - 94B6316E15E4E53F00C7F229 /* ViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 94B6316D15E4E53F00C7F229 /* ViewController.m */; }; - 94B6317115E4E53F00C7F229 /* ViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 94B6316F15E4E53F00C7F229 /* ViewController.xib */; }; 94B6317A15E4E56100C7F229 /* EDStarRating.m in Sources */ = {isa = PBXBuildFile; fileRef = 94B6317915E4E56100C7F229 /* EDStarRating.m */; }; 94B6317E15E4E74A00C7F229 /* star.png in Resources */ = {isa = PBXBuildFile; fileRef = 94B6317B15E4E74A00C7F229 /* star.png */; }; 94B6317F15E4E74A00C7F229 /* starhighlighted.png in Resources */ = {isa = PBXBuildFile; fileRef = 94B6317C15E4E74A00C7F229 /* starhighlighted.png */; }; @@ -28,6 +31,12 @@ /* Begin PBXFileReference section */ 01C5BF7917A3F04800B7B0BC /* Default-568h@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "Default-568h@2x.png"; sourceTree = ""; }; + 5BBC25311824FCEF00B5B592 /* QuartzCore.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = QuartzCore.framework; path = System/Library/Frameworks/QuartzCore.framework; sourceTree = SDKROOT; }; + 5BD3083E1C381D640003AB55 /* Main.storyboard */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.storyboard; path = Main.storyboard; sourceTree = ""; }; + 5BD308401C381D8F0003AB55 /* SampleViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SampleViewController.h; sourceTree = ""; }; + 5BD308411C381D8F0003AB55 /* SampleViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SampleViewController.m; sourceTree = ""; }; + 5BD308431C3847C00003AB55 /* StarLargeEmpty.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = StarLargeEmpty.png; sourceTree = ""; }; + 5BD308441C3847C00003AB55 /* StarLarge.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = StarLarge.png; sourceTree = ""; }; 94B6315615E4E53F00C7F229 /* SampleiOS.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = SampleiOS.app; sourceTree = BUILT_PRODUCTS_DIR; }; 94B6315A15E4E53F00C7F229 /* UIKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = UIKit.framework; path = System/Library/Frameworks/UIKit.framework; sourceTree = SDKROOT; }; 94B6315C15E4E53F00C7F229 /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = System/Library/Frameworks/Foundation.framework; sourceTree = SDKROOT; }; @@ -38,9 +47,6 @@ 94B6316815E4E53F00C7F229 /* SampleiOS-Prefix.pch */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "SampleiOS-Prefix.pch"; sourceTree = ""; }; 94B6316915E4E53F00C7F229 /* AppDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AppDelegate.h; sourceTree = ""; }; 94B6316A15E4E53F00C7F229 /* AppDelegate.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = AppDelegate.m; sourceTree = ""; }; - 94B6316C15E4E53F00C7F229 /* ViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ViewController.h; sourceTree = ""; }; - 94B6316D15E4E53F00C7F229 /* ViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = ViewController.m; sourceTree = ""; }; - 94B6317015E4E53F00C7F229 /* en */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = en; path = en.lproj/ViewController.xib; sourceTree = ""; }; 94B6317815E4E56100C7F229 /* EDStarRating.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = EDStarRating.h; path = ../EDStarRating/EDStarRating.h; sourceTree = ""; }; 94B6317915E4E56100C7F229 /* EDStarRating.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = EDStarRating.m; path = ../EDStarRating/EDStarRating.m; sourceTree = ""; }; 94B6317B15E4E74A00C7F229 /* star.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = star.png; path = ../../sample/sample/star.png; sourceTree = ""; }; @@ -57,6 +63,7 @@ isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( + 5BBC25321824FCEF00B5B592 /* QuartzCore.framework in Frameworks */, 94B6315B15E4E53F00C7F229 /* UIKit.framework in Frameworks */, 94B6315D15E4E53F00C7F229 /* Foundation.framework in Frameworks */, 94B6315F15E4E53F00C7F229 /* CoreGraphics.framework in Frameworks */, @@ -87,6 +94,7 @@ 94B6315915E4E53F00C7F229 /* Frameworks */ = { isa = PBXGroup; children = ( + 5BBC25311824FCEF00B5B592 /* QuartzCore.framework */, 94B6315A15E4E53F00C7F229 /* UIKit.framework */, 94B6315C15E4E53F00C7F229 /* Foundation.framework */, 94B6315E15E4E53F00C7F229 /* CoreGraphics.framework */, @@ -97,6 +105,8 @@ 94B6316015E4E53F00C7F229 /* SampleiOS */ = { isa = PBXGroup; children = ( + 5BD308431C3847C00003AB55 /* StarLargeEmpty.png */, + 5BD308441C3847C00003AB55 /* StarLarge.png */, 94C7B95318805333009CBED2 /* star-highlighted-template.png */, 94C7B95418805333009CBED2 /* star-highlighted-template@2x.png */, 94C7B95518805333009CBED2 /* star-template.png */, @@ -106,10 +116,10 @@ 94B6317C15E4E74A00C7F229 /* starhighlighted.png */, 94B6316915E4E53F00C7F229 /* AppDelegate.h */, 94B6316A15E4E53F00C7F229 /* AppDelegate.m */, - 94B6316C15E4E53F00C7F229 /* ViewController.h */, - 94B6316D15E4E53F00C7F229 /* ViewController.m */, - 94B6316F15E4E53F00C7F229 /* ViewController.xib */, 94B6316115E4E53F00C7F229 /* Supporting Files */, + 5BD3083E1C381D640003AB55 /* Main.storyboard */, + 5BD308401C381D8F0003AB55 /* SampleViewController.h */, + 5BD308411C381D8F0003AB55 /* SampleViewController.m */, ); path = SampleiOS; sourceTree = ""; @@ -161,7 +171,7 @@ 94B6314D15E4E53F00C7F229 /* Project object */ = { isa = PBXProject; attributes = { - LastUpgradeCheck = 0500; + LastUpgradeCheck = 0720; }; buildConfigurationList = 94B6315015E4E53F00C7F229 /* Build configuration list for PBXProject "SampleiOS" */; compatibilityVersion = "Xcode 3.2"; @@ -189,7 +199,9 @@ 94B6316515E4E53F00C7F229 /* InfoPlist.strings in Resources */, 94C7B95A18805333009CBED2 /* star-template@2x.png in Resources */, 94C7B95718805333009CBED2 /* star-highlighted-template.png in Resources */, - 94B6317115E4E53F00C7F229 /* ViewController.xib in Resources */, + 5BD308461C3847C00003AB55 /* StarLarge.png in Resources */, + 5BD308451C3847C00003AB55 /* StarLargeEmpty.png in Resources */, + 5BD3083F1C381D640003AB55 /* Main.storyboard in Resources */, 94B6317E15E4E74A00C7F229 /* star.png in Resources */, 94C7B95818805333009CBED2 /* star-highlighted-template@2x.png in Resources */, 94B6317F15E4E74A00C7F229 /* starhighlighted.png in Resources */, @@ -205,9 +217,9 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( + 5BD308421C381D8F0003AB55 /* SampleViewController.m in Sources */, 94B6316715E4E53F00C7F229 /* main.m in Sources */, 94B6316B15E4E53F00C7F229 /* AppDelegate.m in Sources */, - 94B6316E15E4E53F00C7F229 /* ViewController.m in Sources */, 94B6317A15E4E56100C7F229 /* EDStarRating.m in Sources */, ); runOnlyForDeploymentPostprocessing = 0; @@ -223,14 +235,6 @@ name = InfoPlist.strings; sourceTree = ""; }; - 94B6316F15E4E53F00C7F229 /* ViewController.xib */ = { - isa = PBXVariantGroup; - children = ( - 94B6317015E4E53F00C7F229 /* en */, - ); - name = ViewController.xib; - sourceTree = ""; - }; /* End PBXVariantGroup section */ /* Begin XCBuildConfiguration section */ @@ -244,11 +248,15 @@ CLANG_WARN_EMPTY_BODY = YES; CLANG_WARN_ENUM_CONVERSION = YES; CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_UNREACHABLE_CODE = YES; CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; COPY_PHASE_STRIP = NO; + ENABLE_STRICT_OBJC_MSGSEND = YES; + ENABLE_TESTABILITY = YES; GCC_C_LANGUAGE_STANDARD = gnu99; GCC_DYNAMIC_NO_PIC = NO; + GCC_NO_COMMON_BLOCKS = YES; GCC_OPTIMIZATION_LEVEL = 0; GCC_PREPROCESSOR_DEFINITIONS = ( "DEBUG=1", @@ -262,7 +270,7 @@ GCC_WARN_UNINITIALIZED_AUTOS = YES; GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; - IPHONEOS_DEPLOYMENT_TARGET = 5.1; + IPHONEOS_DEPLOYMENT_TARGET = 7.0; ONLY_ACTIVE_ARCH = YES; SDKROOT = iphoneos; }; @@ -278,10 +286,13 @@ CLANG_WARN_EMPTY_BODY = YES; CLANG_WARN_ENUM_CONVERSION = YES; CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_UNREACHABLE_CODE = YES; CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; COPY_PHASE_STRIP = YES; + ENABLE_STRICT_OBJC_MSGSEND = YES; GCC_C_LANGUAGE_STANDARD = gnu99; + GCC_NO_COMMON_BLOCKS = YES; GCC_VERSION = com.apple.compilers.llvm.clang.1_0; GCC_WARN_64_TO_32_BIT_CONVERSION = YES; GCC_WARN_ABOUT_RETURN_TYPE = YES; @@ -289,7 +300,7 @@ GCC_WARN_UNINITIALIZED_AUTOS = YES; GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; - IPHONEOS_DEPLOYMENT_TARGET = 5.1; + IPHONEOS_DEPLOYMENT_TARGET = 7.0; OTHER_CFLAGS = "-DNS_BLOCK_ASSERTIONS=1"; SDKROOT = iphoneos; VALIDATE_PRODUCT = YES; @@ -302,6 +313,8 @@ GCC_PRECOMPILE_PREFIX_HEADER = YES; GCC_PREFIX_HEADER = "SampleiOS/SampleiOS-Prefix.pch"; INFOPLIST_FILE = "SampleiOS/SampleiOS-Info.plist"; + IPHONEOS_DEPLOYMENT_TARGET = 7.0; + PRODUCT_BUNDLE_IDENTIFIER = "com.cocoawitchurros.${PRODUCT_NAME:rfc1034identifier}"; PRODUCT_NAME = "$(TARGET_NAME)"; WRAPPER_EXTENSION = app; }; @@ -313,6 +326,8 @@ GCC_PRECOMPILE_PREFIX_HEADER = YES; GCC_PREFIX_HEADER = "SampleiOS/SampleiOS-Prefix.pch"; INFOPLIST_FILE = "SampleiOS/SampleiOS-Info.plist"; + IPHONEOS_DEPLOYMENT_TARGET = 7.0; + PRODUCT_BUNDLE_IDENTIFIER = "com.cocoawitchurros.${PRODUCT_NAME:rfc1034identifier}"; PRODUCT_NAME = "$(TARGET_NAME)"; WRAPPER_EXTENSION = app; }; diff --git a/SampleiOS/SampleiOS/AppDelegate.h b/SampleiOS/SampleiOS/AppDelegate.h index 27472bc..bcae85e 100644 --- a/SampleiOS/SampleiOS/AppDelegate.h +++ b/SampleiOS/SampleiOS/AppDelegate.h @@ -14,6 +14,4 @@ @property (strong, nonatomic) UIWindow *window; -@property (strong, nonatomic) ViewController *viewController; - @end diff --git a/SampleiOS/SampleiOS/AppDelegate.m b/SampleiOS/SampleiOS/AppDelegate.m index 81218d0..ef22176 100644 --- a/SampleiOS/SampleiOS/AppDelegate.m +++ b/SampleiOS/SampleiOS/AppDelegate.m @@ -8,20 +8,10 @@ #import "AppDelegate.h" -#import "ViewController.h" - @implementation AppDelegate -@synthesize window = _window; -@synthesize viewController = _viewController; - - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { - self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; - // Override point for customization after application launch. - self.viewController = [[ViewController alloc] initWithNibName:@"ViewController" bundle:nil]; - self.window.rootViewController = self.viewController; - [self.window makeKeyAndVisible]; return YES; } diff --git a/SampleiOS/SampleiOS/Main.storyboard b/SampleiOS/SampleiOS/Main.storyboard new file mode 100644 index 0000000..3727a7f --- /dev/null +++ b/SampleiOS/SampleiOS/Main.storyboard @@ -0,0 +1,107 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/SampleiOS/SampleiOS/SampleViewController.h b/SampleiOS/SampleiOS/SampleViewController.h new file mode 100644 index 0000000..3a68950 --- /dev/null +++ b/SampleiOS/SampleiOS/SampleViewController.h @@ -0,0 +1,21 @@ +// +// SampleViewController.h +// SampleiOS +// +// Created by Martin Pfannemüller on 02.01.16. +// +// + +#import +#import "EDStarRating.h" +@interface SampleViewController : UIViewController + +@property (nonatomic, strong) IBOutlet EDStarRating *starRating; +@property (nonatomic, strong) IBOutlet UILabel *starRatingLabel; +@property (nonatomic, strong) IBOutlet EDStarRating *starRatingImage; +@property (nonatomic, strong) IBOutlet UILabel *starRatingLabelImage; +@property (nonatomic, strong) IBOutlet EDStarRating *starRatingImageLarge; +@property (nonatomic, strong) IBOutlet UILabel *starRatingLabelImageLarge; +@property (nonatomic, copy) NSArray *colors; + +@end diff --git a/SampleiOS/SampleiOS/ViewController.m b/SampleiOS/SampleiOS/SampleViewController.m similarity index 55% rename from SampleiOS/SampleiOS/ViewController.m rename to SampleiOS/SampleiOS/SampleViewController.m index 2e0c79f..d27739a 100644 --- a/SampleiOS/SampleiOS/ViewController.m +++ b/SampleiOS/SampleiOS/SampleViewController.m @@ -1,34 +1,24 @@ // -// ViewController.m +// SampleViewController.m // SampleiOS // -// Created by Ernesto Garcia Carril on 22/08/12. -// Copyright (c) 2012 __MyCompanyName__. All rights reserved. +// Created by Martin Pfannemüller on 02.01.16. // +// + +#import "SampleViewController.h" + +@interface SampleViewController () -#import "ViewController.h" -#import "EDStarRating.h" -@interface ViewController () -@property (weak, nonatomic) IBOutlet EDStarRating *starRating; -@property (weak, nonatomic) IBOutlet UILabel *starRatingLabel; -@property (weak, nonatomic) IBOutlet EDStarRating *starRatingImage; -@property (weak, nonatomic) IBOutlet UILabel *starRatingImageLabel; -@property (strong,nonatomic) NSArray *colors; @end -@implementation ViewController -@synthesize starRating=_starRating; -@synthesize starRatingLabel = _starRatingLabel; -@synthesize starRatingImage = _starRatingImage; -@synthesize starRatingImageLabel = _starRatingImageLabel; +@implementation SampleViewController -- (void)viewDidLoad -{ +- (void)viewDidLoad { [super viewDidLoad]; - self.colors = @[ [UIColor colorWithRed:0.11f green:0.38f blue:0.94f alpha:1.0f], [UIColor colorWithRed:1.0f green:0.22f blue:0.22f alpha:1.0f], [UIColor colorWithRed:0.27f green:0.85f blue:0.46f alpha:1.0f], [UIColor colorWithRed:0.35f green:0.35f blue:0.81f alpha:1.0f]]; - // Setup control using iOS7 tint Color + _starRating.backgroundColor = [UIColor whiteColor]; _starRating.starImage = [[UIImage imageNamed:@"star-template"] imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate]; _starRating.starHighlightedImage = [[UIImage imageNamed:@"star-highlighted-template"] imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate]; @@ -41,7 +31,6 @@ - (void)viewDidLoad [_starRating setNeedsDisplay]; _starRating.tintColor = self.colors[0]; [self starsSelectionChanged:_starRating rating:2.5]; - // Setup control using image _starRatingImage.backgroundImage=[UIImage imageNamed:@"starsbackground iOS.png"]; @@ -53,15 +42,31 @@ - (void)viewDidLoad _starRatingImage.editable=YES; _starRatingImage.rating= 2.5; _starRatingImage.displayMode=EDStarRatingDisplayAccurate; - [self starsSelectionChanged:_starRatingImage rating:2.5]; // This one will use the returnBlock instead of the delegate + __weak typeof(self) weakSelf = self; _starRatingImage.returnBlock = ^(float rating ) { - NSLog(@"ReturnBlock: Star rating changed to %.1f", rating); - // For the sample, Just reuse the other control's delegate method and call it - [self starsSelectionChanged:_starRatingImage rating:rating]; + NSString *ratingString = [NSString stringWithFormat:@"Rating: %.1f", rating]; + weakSelf.starRatingLabelImage.text = ratingString; }; + + // Example with image resizing + // Setup control using image + _starRatingImageLarge.starImage = [UIImage imageNamed:@"StarLargeEmpty.png"]; + _starRatingImageLarge.starHighlightedImage = [UIImage imageNamed:@"StarLarge.png"]; + _starRatingImageLarge.starSize = 20; + _starRatingImageLarge.maxRating = 5.0; + _starRatingImageLarge.delegate = self; + _starRatingImageLarge.horizontalMargin = 12; + _starRatingImageLarge.editable=YES; + _starRatingImageLarge.rating= 2.5; + _starRatingImageLarge.displayMode=EDStarRatingDisplayAccurate; + +} +- (void)didReceiveMemoryWarning { + [super didReceiveMemoryWarning]; + // Dispose of any resources that can be recreated. } -(IBAction)colorChanged:(id)sender @@ -70,30 +75,30 @@ -(IBAction)colorChanged:(id)sender UIColor * color = self.colors[segmentedControl.selectedSegmentIndex]; self.starRating.tintColor = color; - -} -- (void)viewDidUnload -{ - [self setStarRating:nil]; - [self setStarRatingLabel:nil]; - [self setStarRatingImage:nil]; - [self setStarRatingImageLabel:nil]; - [super viewDidUnload]; - // Release any retained subviews of the main view. -} - -- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation -{ - return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown); } -(void)starsSelectionChanged:(EDStarRating *)control rating:(float)rating { NSString *ratingString = [NSString stringWithFormat:@"Rating: %.1f", rating]; - if( [control isEqual:_starRating] ) + + if(control == _starRating){ _starRatingLabel.text = ratingString; - else - _starRatingImageLabel.text = ratingString; + }else if(control == _starRatingImage){ + _starRatingLabelImage.text = ratingString; + }else if(control == _starRatingImageLarge){ + _starRatingLabelImageLarge.text = ratingString; + } + +} + +/* +#pragma mark - Navigation + +// In a storyboard-based application, you will often want to do a little preparation before navigation +- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { + // Get the new view controller using [segue destinationViewController]. + // Pass the selected object to the new view controller. } +*/ @end diff --git a/SampleiOS/SampleiOS/SampleiOS-Info.plist b/SampleiOS/SampleiOS/SampleiOS-Info.plist index b63bf8a..6667e41 100644 --- a/SampleiOS/SampleiOS/SampleiOS-Info.plist +++ b/SampleiOS/SampleiOS/SampleiOS-Info.plist @@ -9,7 +9,7 @@ CFBundleExecutable ${EXECUTABLE_NAME} CFBundleIdentifier - com.cocoawitchurros.${PRODUCT_NAME:rfc1034identifier} + $(PRODUCT_BUNDLE_IDENTIFIER) CFBundleInfoDictionaryVersion 6.0 CFBundleName @@ -24,6 +24,8 @@ 1.0 LSRequiresIPhoneOS + UIMainStoryboardFile + Main UIRequiredDeviceCapabilities armv7 diff --git a/SampleiOS/SampleiOS/StarLarge.png b/SampleiOS/SampleiOS/StarLarge.png new file mode 100644 index 0000000..68525d1 Binary files /dev/null and b/SampleiOS/SampleiOS/StarLarge.png differ diff --git a/SampleiOS/SampleiOS/StarLargeEmpty.png b/SampleiOS/SampleiOS/StarLargeEmpty.png new file mode 100644 index 0000000..373da4d Binary files /dev/null and b/SampleiOS/SampleiOS/StarLargeEmpty.png differ diff --git a/SampleiOS/SampleiOS/ViewController.h b/SampleiOS/SampleiOS/ViewController.h deleted file mode 100644 index 7401b2d..0000000 --- a/SampleiOS/SampleiOS/ViewController.h +++ /dev/null @@ -1,13 +0,0 @@ -// -// ViewController.h -// SampleiOS -// -// Created by Ernesto Garcia Carril on 22/08/12. -// Copyright (c) 2012 __MyCompanyName__. All rights reserved. -// - -#import -#import "EDStarRating.h" -@interface ViewController : UIViewController - -@end diff --git a/SampleiOS/SampleiOS/en.lproj/ViewController.xib b/SampleiOS/SampleiOS/en.lproj/ViewController.xib deleted file mode 100644 index 3f81558..0000000 --- a/SampleiOS/SampleiOS/en.lproj/ViewController.xib +++ /dev/null @@ -1,78 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/edstarrating-ios.png b/edstarrating-ios.png index 072d157..c7d8d44 100644 Binary files a/edstarrating-ios.png and b/edstarrating-ios.png differ