Skip to content

Commit

Permalink
Merge pull request dlinsin#5 from martinjuhasz/master
Browse files Browse the repository at this point in the history
Added the Ability to change Single Star Images in the Rating Control
  • Loading branch information
dlinsin committed Jan 1, 2012
2 parents b93b6af + 904f04c commit ddb94a5
Show file tree
Hide file tree
Showing 11 changed files with 95 additions and 245 deletions.
Binary file added DLStarRating.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions DLStarRating/DLStarRatingControl.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@

- (id)initWithFrame:(CGRect)frame;
- (id)initWithFrame:(CGRect)frame andStars:(NSUInteger)_numberOfStars;
- (void)setStar:(UIImage*)defaultStarImage highlightedStar:(UIImage*)highlightedStarImage atIndex:(int)index;

@property (retain,nonatomic) UIImage *star;
@property (retain,nonatomic) UIImage *highlightedStar;
Expand Down
18 changes: 17 additions & 1 deletion DLStarRating/DLStarRatingControl.m
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,22 @@ - (void)layoutSubviews {
}
}

#pragma mark -
#pragma mark Customization

- (void)setStar:(UIImage*)defaultStarImage highlightedStar:(UIImage*)highlightedStarImage atIndex:(int)index {
DLStarView *selectedStar = (DLStarView*)[self subViewWithTag:index];

// check if star exists
if (!selectedStar) return;

// check images for nil else use default stars
defaultStarImage = (defaultStarImage) ? defaultStarImage : star;
highlightedStarImage = (highlightedStarImage) ? highlightedStarImage : highlightedStar;

[selectedStar setStarImage:defaultStarImage highlightedStarImage:highlightedStarImage];
}

#pragma mark -
#pragma mark Touch Handling

Expand All @@ -75,7 +91,7 @@ - (UIButton*)starForPoint:(CGPoint)point {
if (CGRectContainsPoint([self subViewWithTag:i].frame, point)) {
return (UIButton*)[self subViewWithTag:i];
}
}
}
return nil;
}

Expand Down
1 change: 1 addition & 0 deletions DLStarRating/DLStarView.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,6 @@

- (id)initWithDefault:(UIImage*)star highlighted:(UIImage*)highlightedStar position:(int)index;
- (void)centerIn:(CGRect)_frame with:(int)numberOfStars;
- (void)setStarImage:(UIImage*)starImage highlightedStarImage:(UIImage*)highlightedImage;

@end
10 changes: 7 additions & 3 deletions DLStarRating/DLStarView.m
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,7 @@ @implementation DLStarView
- (id)initWithDefault:(UIImage*)star highlighted:(UIImage*)highlightedStar position:(int)index {
self = [super initWithFrame:CGRectMake((star.size.width*index), 0, star.size.width, star.size.height+kEdgeInsetBottom)];
if (self) {
[self setImage:star forState:UIControlStateNormal];
[self setImage:highlightedStar forState:UIControlStateSelected];
[self setImage:highlightedStar forState:UIControlStateHighlighted];
[self setStarImage:star highlightedStarImage:highlightedStar];
[self setTag:index];
[self setImageEdgeInsets:UIEdgeInsetsMake(0, 0, kEdgeInsetBottom, 0)];
[self setBackgroundColor:[UIColor clearColor]];
Expand Down Expand Up @@ -55,4 +53,10 @@ - (void)centerIn:(CGRect)_frame with:(int)numberOfStars {
self.frame = CGRectMake((size.width*self.tag) + gapToApply, newY, size.width, size.height);
}

- (void)setStarImage:(UIImage*)starImage highlightedStarImage:(UIImage*)highlightedImage {
[self setImage:starImage forState:UIControlStateNormal];
[self setImage:highlightedImage forState:UIControlStateSelected];
[self setImage:highlightedImage forState:UIControlStateHighlighted];
}

@end
Binary file added DLStarRating/images/star_highlighted-darker.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
19 changes: 18 additions & 1 deletion DLStarRatingDemo/Classes/DLStarRatingDemoViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,29 @@ @implementation DLStarRatingDemoViewController

- (void)viewDidLoad {
[super viewDidLoad];
DLStarRatingControl *customNumberOfStars = [[DLStarRatingControl alloc] initWithFrame:CGRectMake(0, 230, 320, 230) andStars:3];

// Custom Number of Stars
DLStarRatingControl *customNumberOfStars = [[DLStarRatingControl alloc] initWithFrame:CGRectMake(0, 154, 320, 153) andStars:3];
customNumberOfStars.backgroundColor = [UIColor groupTableViewBackgroundColor];
customNumberOfStars.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleBottomMargin;
customNumberOfStars.rating = 2;
[self.view addSubview:customNumberOfStars];
[customNumberOfStars release];

// Custom Images
DLStarRatingControl *customStarImageControl = [[DLStarRatingControl alloc] initWithFrame:CGRectMake(0.0, 307.0, 320.0, 153.0)];

// Set Custom Stars
[customStarImageControl setStar:nil highlightedStar:[UIImage imageNamed:@"star_highlighted-darker.png"] atIndex:0];
[customStarImageControl setStar:nil highlightedStar:[UIImage imageNamed:@"star_highlighted-darker.png"] atIndex:2];
[customStarImageControl setStar:nil highlightedStar:[UIImage imageNamed:@"star_highlighted-darker.png"] atIndex:4];

customStarImageControl.backgroundColor = [UIColor lightGrayColor];
customStarImageControl.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleBottomMargin;
customStarImageControl.rating = 3;
[self.view addSubview:customStarImageControl];
[customStarImageControl release];

}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
Expand Down
15 changes: 11 additions & 4 deletions DLStarRatingDemo/DLStarRatingDemo.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
archiveVersion = 1;
classes = {
};
objectVersion = 45;
objectVersion = 46;
objects = {

/* Begin PBXBuildFile section */
Expand All @@ -15,6 +15,8 @@
2899E5220DE3E06400AC0155 /* DLStarRatingDemoViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 2899E5210DE3E06400AC0155 /* DLStarRatingDemoViewController.xib */; };
28AD733F0D9D9553002E5188 /* MainWindow.xib in Resources */ = {isa = PBXBuildFile; fileRef = 28AD733E0D9D9553002E5188 /* MainWindow.xib */; };
28D7ACF80DDB3853001CB0EB /* DLStarRatingDemoViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 28D7ACF70DDB3853001CB0EB /* DLStarRatingDemoViewController.m */; };
7A59F61D147016F7005CC3C0 /* star_highlighted-darker.png in Resources */ = {isa = PBXBuildFile; fileRef = 7A59F61B147016F7005CC3C0 /* star_highlighted-darker.png */; };
7A59F61E147016F7005CC3C0 /* star_highlighted-darker@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = 7A59F61C147016F7005CC3C0 /* star_highlighted-darker@2x.png */; };
B6910FFC130E816600105663 /* star_highlighted@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = B6910FFA130E816600105663 /* star_highlighted@2x.png */; };
B6910FFD130E816600105663 /* star@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = B6910FFB130E816600105663 /* star@2x.png */; };
B6E998D212D74B0F00141730 /* DLStarRatingControl.m in Sources */ = {isa = PBXBuildFile; fileRef = B6E998CA12D74B0F00141730 /* DLStarRatingControl.m */; };
Expand All @@ -37,6 +39,8 @@
28D7ACF70DDB3853001CB0EB /* DLStarRatingDemoViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = DLStarRatingDemoViewController.m; sourceTree = "<group>"; };
29B97316FDCFA39411CA2CEA /* main.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = "<group>"; };
32CA4F630368D1EE00C91783 /* DLStarRatingDemo_Prefix.pch */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DLStarRatingDemo_Prefix.pch; sourceTree = "<group>"; };
7A59F61B147016F7005CC3C0 /* star_highlighted-darker.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "star_highlighted-darker.png"; sourceTree = "<group>"; };
7A59F61C147016F7005CC3C0 /* star_highlighted-darker@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "star_highlighted-darker@2x.png"; sourceTree = "<group>"; };
8D1107310486CEB800E47090 /* DLStarRatingDemo-Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = "DLStarRatingDemo-Info.plist"; plistStructureDefinitionIdentifier = "com.apple.xcode.plist.structure-definition.iphone.info-plist"; sourceTree = "<group>"; };
B6910FFA130E816600105663 /* star_highlighted@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "star_highlighted@2x.png"; sourceTree = "<group>"; };
B6910FFB130E816600105663 /* star@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "star@2x.png"; sourceTree = "<group>"; };
Expand Down Expand Up @@ -147,6 +151,8 @@
B6910FFB130E816600105663 /* star@2x.png */,
B6E998CE12D74B0F00141730 /* star.png */,
B6E998CF12D74B0F00141730 /* star_highlighted.png */,
7A59F61B147016F7005CC3C0 /* star_highlighted-darker.png */,
7A59F61C147016F7005CC3C0 /* star_highlighted-darker@2x.png */,
);
path = images;
sourceTree = "<group>";
Expand Down Expand Up @@ -177,10 +183,11 @@
29B97313FDCFA39411CA2CEA /* Project object */ = {
isa = PBXProject;
attributes = {
LastUpgradeCheck = 0420;
ORGANIZATIONNAME = furryfishApps.com;
};
buildConfigurationList = C01FCF4E08A954540054247B /* Build configuration list for PBXProject "DLStarRatingDemo" */;
compatibilityVersion = "Xcode 3.1";
compatibilityVersion = "Xcode 3.2";
developmentRegion = English;
hasScannedForEncodings = 1;
knownRegions = (
Expand Down Expand Up @@ -209,6 +216,8 @@
B6E998D512D74B0F00141730 /* star_highlighted.png in Resources */,
B6910FFC130E816600105663 /* star_highlighted@2x.png in Resources */,
B6910FFD130E816600105663 /* star@2x.png in Resources */,
7A59F61D147016F7005CC3C0 /* star_highlighted-darker.png in Resources */,
7A59F61E147016F7005CC3C0 /* star_highlighted-darker@2x.png in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down Expand Up @@ -269,7 +278,6 @@
GCC_WARN_ABOUT_RETURN_TYPE = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 3.1.3;
PREBINDING = NO;
SDKROOT = iphoneos;
};
name = Debug;
Expand All @@ -284,7 +292,6 @@
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 3.1.3;
OTHER_CFLAGS = "-DNS_BLOCK_ASSERTIONS=1";
PREBINDING = NO;
SDKROOT = iphoneos;
};
name = Release;
Expand Down
Loading

0 comments on commit ddb94a5

Please sign in to comment.