Skip to content

Instantly share code, notes, and snippets.

@imrekel
Created September 21, 2012 08:57

Revisions

  1. imrekel revised this gist Sep 27, 2012. 1 changed file with 9 additions and 0 deletions.
    9 changes: 9 additions & 0 deletions IPColorColorPicker-drawRect.m
    Original file line number Diff line number Diff line change
    @@ -11,5 +11,14 @@ - (void)drawRect:(CGRect)rect
    CGFloat colorWidth = self.bounds.size.width/kColorCount;
    CGContextFillRect(context, CGRectMake(colorWidth*i, 0,
    colorWidth, self.bounds.size.height));

    /*
    if (i == _selectedColorIndex)
    {
    [[UIColor blackColor] setStroke];
    CGContextSetLineWidth(context, 2.0);
    CGContextStrokeRect(context, CGRectMake(colorWidth*i, 1, colorWidth-1, self.bounds.size.height-1));
    }
    */
    }
    }
  2. imrekel revised this gist Sep 21, 2012. 1 changed file with 11 additions and 0 deletions.
    11 changes: 11 additions & 0 deletions IPColorPicker-handleTap.m
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,11 @@
    - (void)handleTap:(UITapGestureRecognizer*)gestureRecognizer
    {
    CGPoint tapPoint = [gestureRecognizer locationInView:self];
    CGFloat colorWidth = self.bounds.size.width/kColorCount;

    _selectedColorIndex = tapPoint.x / colorWidth;
    _selectedColor = [UIColor colorWithHue:_selectedColorIndex*(1.0/kColorCount)
    saturation:1.0 brightness:1.0 alpha:1.0];

    [self setNeedsDisplay];
    }
  3. imrekel revised this gist Sep 21, 2012. 1 changed file with 9 additions and 0 deletions.
    9 changes: 9 additions & 0 deletions IPColorPicker-initWithCoder.m
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,9 @@
    - (id)initWithCoder:(NSCoder*)coder
    {
    self = [super initWithCoder:coder];
    if (self) {
    self.selectedColor = [UIColor colorWithHue:0.0 saturation:1.0 brightness:1.0 alpha:1.0];
    _selectedColorIndex = 0;
    }
    return self;
    }
  4. imrekel revised this gist Sep 21, 2012. 1 changed file with 15 additions and 0 deletions.
    15 changes: 15 additions & 0 deletions IPColorColorPicker-drawRect.m
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,15 @@
    - (void)drawRect:(CGRect)rect
    {
    CGContextRef context = UIGraphicsGetCurrentContext();

    for (int i=0; i<kColorCount; i++)
    {
    UIColor* color = [UIColor colorWithHue:i*(1.0/kColorCount)
    saturation:1.0 brightness:1.0 alpha:1.0];
    [color setFill];

    CGFloat colorWidth = self.bounds.size.width/kColorCount;
    CGContextFillRect(context, CGRectMake(colorWidth*i, 0,
    colorWidth, self.bounds.size.height));
    }
    }
  5. imrekel revised this gist Sep 21, 2012. 2 changed files with 2 additions and 2 deletions.
    2 changes: 1 addition & 1 deletion IPViewController-drawCircleWithCenter.m
    Original file line number Diff line number Diff line change
    @@ -1,7 +1,7 @@
    - (void)drawCircleWithCenter: (CGPoint)center radius: (CGFloat)radius color:(UIColor*)color
    {
    // Új grafikus kontextus létrehozása, képre való rajzoláshoz
    UIGraphicsBeginImageContextWithOptions(CGSizeMake(self.canvas.bounds.size, [UIScreen mainScreen].bounds.size.height), NO, [[UIScreen mainScreen] scale]);
    UIGraphicsBeginImageContextWithOptions(self.canvas.bounds.size, NO, [[UIScreen mainScreen] scale]);

    // Ha már van valami a képen, akkor azt kirajzoljuk az új grafikus kontextusra
    // UIImage drawAtPoint automatikusan az aktuális grafikus kontextust használja
    2 changes: 1 addition & 1 deletion IPViewController-drawSquareWithCenter.m
    Original file line number Diff line number Diff line change
    @@ -1,7 +1,7 @@
    - (void)drawSquareWithCenter: (CGPoint)center width: (CGFloat)width color:(UIColor*)color
    {
    // Új grafikus kontextus létrehozása, képre való rajzoláshoz
    UIGraphicsBeginImageContextWithOptions(CGSizeMake([UIScreen mainScreen].bounds.size.height, [UIScreen mainScreen].bounds.size.height), NO, [[UIScreen mainScreen] scale]);
    UIGraphicsBeginImageContextWithOptions(self.canvas.bounds.size, NO, [[UIScreen mainScreen] scale]);

    // Ha már van valami a képen, akkor azt kirajzoljuk az új grafikus kontextusra
    // UIImage drawAtPoint automatikusan az aktuális grafikus kontextust használja
  6. imrekel revised this gist Sep 21, 2012. 1 changed file with 21 additions and 0 deletions.
    21 changes: 21 additions & 0 deletions IPViewController-drawSquareWithCenter.m
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,21 @@
    - (void)drawSquareWithCenter: (CGPoint)center width: (CGFloat)width color:(UIColor*)color
    {
    // Új grafikus kontextus létrehozása, képre való rajzoláshoz
    UIGraphicsBeginImageContextWithOptions(CGSizeMake([UIScreen mainScreen].bounds.size.height, [UIScreen mainScreen].bounds.size.height), NO, [[UIScreen mainScreen] scale]);

    // Ha már van valami a képen, akkor azt kirajzoljuk az új grafikus kontextusra
    // UIImage drawAtPoint automatikusan az aktuális grafikus kontextust használja
    if (self.canvas.image)
    [self.canvas.image drawAtPoint:CGPointZero];

    // Grafikus kontextus elkérése és rajzolás
    CGContextRef context = UIGraphicsGetCurrentContext();
    [color setStroke];
    [color setFill];
    CGContextFillRect(context, CGRectMake(center.x-width/2, center.y-width/2, width, width));

    // A grafikus kontextus tartalmának lekérése egy UIImage-ben, majd
    // ennek beállítása a UIImageView-hez
    self.canvas.image = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    }
  7. imrekel renamed this gist Sep 21, 2012. 1 changed file with 0 additions and 0 deletions.
  8. imrekel created this gist Sep 21, 2012.
    21 changes: 21 additions & 0 deletions IPViewController-drawCircleWithCenter
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,21 @@
    - (void)drawCircleWithCenter: (CGPoint)center radius: (CGFloat)radius color:(UIColor*)color
    {
    // Új grafikus kontextus létrehozása, képre való rajzoláshoz
    UIGraphicsBeginImageContextWithOptions(CGSizeMake(self.canvas.bounds.size, [UIScreen mainScreen].bounds.size.height), NO, [[UIScreen mainScreen] scale]);

    // Ha már van valami a képen, akkor azt kirajzoljuk az új grafikus kontextusra
    // UIImage drawAtPoint automatikusan az aktuális grafikus kontextust használja
    if (self.canvas.image)
    [self.canvas.image drawAtPoint:CGPointZero];

    // Grafikus kontextus elkérése és rajzolás
    CGContextRef context = UIGraphicsGetCurrentContext();
    [color setStroke];
    [color setFill];
    CGContextFillEllipseInRect(context, CGRectMake(center.x-radius, center.y-radius, radius*2, radius*2));

    // A grafikus kontextus tartalmának lekérése egy UIImage-ben, majd
    // ennek beállítása a UIImageView-hez
    self.canvas.image = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    }