Skip to content

Commit 79c77cf

Browse files
committed
Refactor common setup code into separate method
1 parent 1879391 commit 79c77cf

File tree

1 file changed

+14
-8
lines changed

1 file changed

+14
-8
lines changed

DYRateView/DYRateView/DYRateView.m

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
3232

3333
@interface DYRateView ()
3434

35+
- (void)commonSetup;
3536
- (void)handleTouchAtLocation:(CGPoint)location;
3637
- (void)notifyDelegate;
3738

@@ -57,10 +58,8 @@ - (DYRateView *)initWithFrame:(CGRect)frame fullStar:(UIImage *)fullStarImage em
5758

5859
_fullStarImage = [fullStarImage retain];
5960
_emptyStarImage = [emptyStarImage retain];
60-
_padding = 4;
61-
_numOfStars = 5;
62-
self.alignment = RateViewAlignmentLeft;
63-
self.editable = NO;
61+
62+
[self commonSetup];
6463
}
6564
return self;
6665
}
@@ -70,10 +69,8 @@ - (id)initWithCoder:(NSCoder *)decoder {
7069
if (self) {
7170
_fullStarImage = [[UIImage imageNamed:DefaultFullStarImageFilename] retain];
7271
_emptyStarImage = [[UIImage imageNamed:DefaultEmptyStarImageFilename] retain];
73-
_padding = 4;
74-
_numOfStars = 5;
75-
self.alignment = RateViewAlignmentLeft;
76-
self.editable = NO;
72+
73+
[self commonSetup];
7774
}
7875
return self;
7976
}
@@ -84,6 +81,15 @@ - (void)dealloc {
8481
[super dealloc];
8582
}
8683

84+
- (void)commonSetup
85+
{
86+
// Include the initialization code that is common to initWithFrame:
87+
// and initWithCoder: here.
88+
_padding = 4;
89+
_numOfStars = 5;
90+
self.alignment = RateViewAlignmentLeft;
91+
self.editable = NO;
92+
}
8793

8894
- (void)drawRect:(CGRect)rect
8995
{

0 commit comments

Comments
 (0)