|
//
// LSDotLayer.m
// ViewSwitcher
//
// Created by Le Son on 6/10/10.
// Copyright 2010 __MyCompanyName__. All rights reserved.
//
#import "LSDotLayer.h"
@implementation LSDotLayer
@dynamic numberOfDots;
@dynamic activeDot;
- (NSUInteger)numberOfDots
{
return numberOfDots;
}
- (void)setNumberOfDots:(NSUInteger)n
{
numberOfDots = n;
[self setNeedsDisplay];
}
- (NSUInteger)activeDot
{
return activeDot;
}
- (void)setActiveDot:(NSUInteger)n
{
activeDot = n;
[self setNeedsDisplay];
}
- (void)drawInContext:(CGContextRef)ctx
{
if (numberOfDots > 1)
{
// Diameter = height of this layer
float diameter = self.bounds.size.height;
// Get center point
CGPoint center = CGPointMake(CGRectGetMidX(self.bounds), CGRectGetMidY(self.bounds));
// Get point of first dot
float x = center.x - (diameter + 10.0f) * self.numberOfDots/2 + 10.0f;
float y = center.y;
CGPoint pos = CGPointMake(x, y);
for (int i = 0; i < self.numberOfDots; i++)
{
// Referenced from http://alanduncan.net/old/index.php?q=node/4
// Draw the dot
CGContextSetRGBFillColor(ctx, 1.0f, 1.0f, 1.0f, (i == self.activeDot ? 1.0f : 0.5f));
float radius = diameter * 0.5;
CGRect myOval = CGRectMake(pos.x - radius, pos.y - radius, diameter, diameter);
CGContextAddEllipseInRect(ctx, myOval);
CGContextFillPath(ctx);
CGContextStrokePath(ctx);
// Increase pos
pos.x += diameter + 10.0f;
}
}
}
@end
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
I'm a 16 year old high school student. I know some about Objective-C and a bit about C#, mostly through reading stuff online.