Skip to content

Commit

Permalink
- more code cleaning
Browse files Browse the repository at this point in the history
  • Loading branch information
honcheng committed Aug 16, 2012
1 parent bc29999 commit 86070a3
Showing 1 changed file with 38 additions and 38 deletions.
76 changes: 38 additions & 38 deletions StyledPageControlDemo/PageControlDemo/StyledPageControl.m
Expand Up @@ -113,13 +113,13 @@ - (void)drawRect:(CGRect)rect
{ {
UIColor *coreNormalColor, *coreSelectedColor, *strokeNormalColor, *strokeSelectedColor; UIColor *coreNormalColor, *coreSelectedColor, *strokeNormalColor, *strokeSelectedColor;


if (_coreNormalColor) coreNormalColor = _coreNormalColor; if (self.coreNormalColor) coreNormalColor = self.coreNormalColor;
else coreNormalColor = COLOR_GRAYISHBLUE; else coreNormalColor = COLOR_GRAYISHBLUE;


if (_coreSelectedColor) coreSelectedColor = _coreSelectedColor; if (self.coreSelectedColor) coreSelectedColor = self.coreSelectedColor;
else else
{ {
if (_pageControlStyle==PageControlStyleStrokedCircle || _pageControlStyle==PageControlStyleWithPageNumber) if (self.pageControlStyle==PageControlStyleStrokedCircle || self.pageControlStyle==PageControlStyleWithPageNumber)
{ {
coreSelectedColor = COLOR_GRAYISHBLUE; coreSelectedColor = COLOR_GRAYISHBLUE;
} }
Expand All @@ -129,12 +129,12 @@ - (void)drawRect:(CGRect)rect
} }
} }


if (_strokeNormalColor) strokeNormalColor = _strokeNormalColor; if (self.strokeNormalColor) strokeNormalColor = self.strokeNormalColor;
else else
{ {
if (_pageControlStyle==PageControlStyleDefault && _coreNormalColor) if (self.pageControlStyle==PageControlStyleDefault && self.coreNormalColor)
{ {
strokeNormalColor = _coreNormalColor; strokeNormalColor = self.coreNormalColor;
} }
else else
{ {
Expand All @@ -143,16 +143,16 @@ - (void)drawRect:(CGRect)rect


} }


if (_strokeSelectedColor) strokeSelectedColor = _strokeSelectedColor; if (self.strokeSelectedColor) strokeSelectedColor = self.strokeSelectedColor;
else else
{ {
if (_pageControlStyle==PageControlStyleStrokedCircle || _pageControlStyle==PageControlStyleWithPageNumber) if (self.pageControlStyle==PageControlStyleStrokedCircle || self.pageControlStyle==PageControlStyleWithPageNumber)
{ {
strokeSelectedColor = COLOR_GRAYISHBLUE; strokeSelectedColor = COLOR_GRAYISHBLUE;
} }
else if (_pageControlStyle==PageControlStyleDefault && _coreSelectedColor) else if (self.pageControlStyle==PageControlStyleDefault && self.coreSelectedColor)
{ {
strokeSelectedColor = _coreSelectedColor; strokeSelectedColor = self.coreSelectedColor;
} }
else else
{ {
Expand All @@ -161,25 +161,25 @@ - (void)drawRect:(CGRect)rect
} }


// Drawing code // Drawing code
if (_hidesForSinglePage && _numberOfPages==1) if (self.hidesForSinglePage && self.numberOfPages==1)
{ {
return; return;
} }


CGContextRef myContext = UIGraphicsGetCurrentContext(); CGContextRef myContext = UIGraphicsGetCurrentContext();


int gap = _gapWidth; int gap = self.gapWidth;
float diameter = _diameter - 2*_strokeWidth; float diameter = self.diameter - 2*self.strokeWidth;


if (self.pageControlStyle==PageControlStyleThumb) if (self.pageControlStyle==PageControlStyleThumb)
{ {
if (_thumbImage && _selectedThumbImage) if (self.thumbImage && self.selectedThumbImage)
{ {
diameter = _thumbImage.size.width; diameter = self.thumbImage.size.width;
} }
} }


int total_width = _numberOfPages*diameter + (_numberOfPages-1)*gap; int total_width = self.numberOfPages*diameter + (self.numberOfPages-1)*gap;


if (total_width>self.frame.size.width) if (total_width>self.frame.size.width)
{ {
Expand All @@ -190,33 +190,33 @@ - (void)drawRect:(CGRect)rect
while (total_width>self.frame.size.width) while (total_width>self.frame.size.width)
{ {
gap -= 1; gap -= 1;
total_width = _numberOfPages*diameter + (_numberOfPages-1)*gap; total_width = self.numberOfPages*diameter + (self.numberOfPages-1)*gap;


if (gap==2) if (gap==2)
{ {
break; break;
total_width = _numberOfPages*diameter + (_numberOfPages-1)*gap; total_width = self.numberOfPages*diameter + (self.numberOfPages-1)*gap;
} }
} }


if (diameter==2) if (diameter==2)
{ {
break; break;
total_width = _numberOfPages*diameter + (_numberOfPages-1)*gap; total_width = self.numberOfPages*diameter + (self.numberOfPages-1)*gap;
} }
} }




} }


int i; int i;
for (i=0; i<_numberOfPages; i++) for (i=0; i<self.numberOfPages; i++)
{ {
int x = (self.frame.size.width-total_width)/2 + i*(diameter+gap); int x = (self.frame.size.width-total_width)/2 + i*(diameter+gap);


if (_pageControlStyle==PageControlStyleDefault) if (self.pageControlStyle==PageControlStyleDefault)
{ {
if (i==_currentPage) if (i==self.currentPage)
{ {
CGContextSetFillColorWithColor(myContext, [coreSelectedColor CGColor]); CGContextSetFillColorWithColor(myContext, [coreSelectedColor CGColor]);
CGContextFillEllipseInRect(myContext, CGRectMake(x,(self.frame.size.height-diameter)/2,diameter,diameter)); CGContextFillEllipseInRect(myContext, CGRectMake(x,(self.frame.size.height-diameter)/2,diameter,diameter));
Expand All @@ -231,10 +231,10 @@ - (void)drawRect:(CGRect)rect
CGContextStrokeEllipseInRect(myContext, CGRectMake(x,(self.frame.size.height-diameter)/2,diameter,diameter)); CGContextStrokeEllipseInRect(myContext, CGRectMake(x,(self.frame.size.height-diameter)/2,diameter,diameter));
} }
} }
else if (_pageControlStyle==PageControlStyleStrokedCircle) else if (self.pageControlStyle==PageControlStyleStrokedCircle)
{ {
CGContextSetLineWidth(myContext, _strokeWidth); CGContextSetLineWidth(myContext, self.strokeWidth);
if (i==_currentPage) if (i==self.currentPage)
{ {
CGContextSetFillColorWithColor(myContext, [coreSelectedColor CGColor]); CGContextSetFillColorWithColor(myContext, [coreSelectedColor CGColor]);
CGContextFillEllipseInRect(myContext, CGRectMake(x,(self.frame.size.height-diameter)/2,diameter,diameter)); CGContextFillEllipseInRect(myContext, CGRectMake(x,(self.frame.size.height-diameter)/2,diameter,diameter));
Expand All @@ -247,10 +247,10 @@ - (void)drawRect:(CGRect)rect
CGContextStrokeEllipseInRect(myContext, CGRectMake(x,(self.frame.size.height-diameter)/2,diameter,diameter)); CGContextStrokeEllipseInRect(myContext, CGRectMake(x,(self.frame.size.height-diameter)/2,diameter,diameter));
} }
} }
else if (_pageControlStyle==PageControlStyleWithPageNumber) else if (self.pageControlStyle==PageControlStyleWithPageNumber)
{ {
CGContextSetLineWidth(myContext, _strokeWidth); CGContextSetLineWidth(myContext, self.strokeWidth);
if (i==_currentPage) if (i==self.currentPage)
{ {
int _currentPageDiameter = diameter*1.6; int _currentPageDiameter = diameter*1.6;
x = (self.frame.size.width-total_width)/2 + i*(diameter+gap) - (_currentPageDiameter-diameter)/2; x = (self.frame.size.width-total_width)/2 + i*(diameter+gap) - (_currentPageDiameter-diameter)/2;
Expand All @@ -269,21 +269,21 @@ - (void)drawRect:(CGRect)rect
CGContextStrokeEllipseInRect(myContext, CGRectMake(x,(self.frame.size.height-diameter)/2,diameter,diameter)); CGContextStrokeEllipseInRect(myContext, CGRectMake(x,(self.frame.size.height-diameter)/2,diameter,diameter));
} }
} }
else if (_pageControlStyle==PageControlStylePressed1 || _pageControlStyle==PageControlStylePressed2) else if (self.pageControlStyle==PageControlStylePressed1 || self.pageControlStyle==PageControlStylePressed2)
{ {
if (_pageControlStyle==PageControlStylePressed1) if (self.pageControlStyle==PageControlStylePressed1)
{ {
CGContextSetFillColorWithColor(myContext, [[UIColor colorWithRed:0 green:0 blue:0 alpha:1] CGColor]); CGContextSetFillColorWithColor(myContext, [[UIColor colorWithRed:0 green:0 blue:0 alpha:1] CGColor]);
CGContextFillEllipseInRect(myContext, CGRectMake(x,(self.frame.size.height-diameter)/2-1,diameter,diameter)); CGContextFillEllipseInRect(myContext, CGRectMake(x,(self.frame.size.height-diameter)/2-1,diameter,diameter));
} }
else if (_pageControlStyle==PageControlStylePressed2) else if (self.pageControlStyle==PageControlStylePressed2)
{ {
CGContextSetFillColorWithColor(myContext, [[UIColor colorWithRed:0.9 green:0.9 blue:0.9 alpha:1] CGColor]); CGContextSetFillColorWithColor(myContext, [[UIColor colorWithRed:0.9 green:0.9 blue:0.9 alpha:1] CGColor]);
CGContextFillEllipseInRect(myContext, CGRectMake(x,(self.frame.size.height-diameter)/2+1,diameter,diameter)); CGContextFillEllipseInRect(myContext, CGRectMake(x,(self.frame.size.height-diameter)/2+1,diameter,diameter));
} }




if (i==_currentPage) if (i==self.currentPage)
{ {
CGContextSetFillColorWithColor(myContext, [coreSelectedColor CGColor]); CGContextSetFillColorWithColor(myContext, [coreSelectedColor CGColor]);
CGContextFillEllipseInRect(myContext, CGRectMake(x,(self.frame.size.height-diameter)/2,diameter,diameter)); CGContextFillEllipseInRect(myContext, CGRectMake(x,(self.frame.size.height-diameter)/2,diameter,diameter));
Expand All @@ -300,18 +300,18 @@ - (void)drawRect:(CGRect)rect
} }
else if (self.pageControlStyle==PageControlStyleThumb) else if (self.pageControlStyle==PageControlStyleThumb)
{ {
UIImage* aThumbImage = [self thumbImageForIndex:i]; UIImage* thumbImage = [self thumbImageForIndex:i];
UIImage* aSelectedThumbImage = [self selectedThumbImageForIndex:i]; UIImage* selectedThumbImage = [self selectedThumbImageForIndex:i];


if (aThumbImage && aSelectedThumbImage) if (thumbImage && selectedThumbImage)
{ {
if (i==_currentPage) if (i==self.currentPage)
{ {
[aSelectedThumbImage drawInRect:CGRectMake(x,(self.frame.size.height-aSelectedThumbImage.size.height)/2,aSelectedThumbImage.size.width,aSelectedThumbImage.size.height)]; [selectedThumbImage drawInRect:CGRectMake(x,(self.frame.size.height-selectedThumbImage.size.height)/2,selectedThumbImage.size.width,selectedThumbImage.size.height)];
} }
else else
{ {
[aThumbImage drawInRect:CGRectMake(x,(self.frame.size.height-aThumbImage.size.height)/2,aThumbImage.size.width,aThumbImage.size.height)]; [thumbImage drawInRect:CGRectMake(x,(self.frame.size.height-thumbImage.size.height)/2,thumbImage.size.width,thumbImage.size.height)];
} }
} }
} }
Expand Down

0 comments on commit 86070a3

Please sign in to comment.