Core Graphics Tutorial: Arcs and Paths

Discussion of the official tutorials published on raywenderlich.com. Please only discuss the official tutorials here - for general questions, use the General Discussion forum instead.

Core Graphics Tutorial: Arcs and Paths

Postby rwenderlich » Wed Apr 17, 2013 11:00 am

This is the official thread to discuss the following blog post: Core Graphics Tutorial: Arcs and Paths
- - - - - - - - - - - - - - - - - - - - - - - - - - - -
Ray Wenderlich
Blog: http://www.raywenderlich.com
Twitter: http://twitter.com/rwenderlich
- - - - - - - - - - - - - - - - - - - - - - - - - - - -
User avatar
rwenderlich
Site Admin
 
Posts: 2268
Joined: Thu Dec 23, 2010 4:14 pm
Has thanked: 28 times
Been thanked: 381 times

Re: Core Graphics Tutorial: Arcs and Paths

Postby phoward8020 » Tue Apr 23, 2013 3:20 am

I was unable to replicate the results in the "Finishing Touches" section until I moved the CGContextStrokeRect call into the !self.lastCell conditional:

Code: Select all
if (!self.lastCell) {
       
        CGContextStrokeRect(context, strokeRect);
        draw1PxStroke(context, startPoint, endPoint, separatorColor.CGColor);
       
    } else {

// ...and so on...


Did I miss something?
phoward8020
n00b
 
Posts: 3
Joined: Tue May 01, 2012 4:43 pm
Has thanked: 0 time
Been thanked: 1 time

Re: Core Graphics Tutorial: Arcs and Paths

Postby solomon » Tue Apr 23, 2013 5:31 am

Same issue.. great tutorial though

Should probably read:

Code: Select all

if (!self.lastCell) {
        CGRect strokeRect = paperRect;
        strokeRect.size.height -= 1;
        strokeRect = rectFor1PxStroke(strokeRect);
        CGContextSetStrokeColorWithColor(context, whiteColor.CGColor);
       
        CGContextSetLineWidth(context, 1.0);
        CGContextStrokeRect(context, strokeRect);

        CGPoint startPoint = CGPointMake(paperRect.origin.x, paperRect.origin.y + paperRect.size.height - 1);
        CGPoint endPoint = CGPointMake(paperRect.origin.x + paperRect.size.width - 1, paperRect.origin.y + paperRect.size.height - 1);
        draw1PxStroke(context, startPoint, endPoint, separatorColor.CGColor);
    } else {
        CGContextSetStrokeColorWithColor(context, whiteColor.CGColor);
        CGContextSetLineWidth(context, 1.0);
       
        CGPoint pointA = CGPointMake(paperRect.origin.x, paperRect.origin.y + paperRect.size.height - 1);
        CGPoint pointB = CGPointMake(paperRect.origin.x, paperRect.origin.y);
        CGPoint pointC = CGPointMake(paperRect.origin.x + paperRect.size.width - 1, paperRect.origin.y);
        CGPoint pointD = CGPointMake(paperRect.origin.x + paperRect.size.width - 1, paperRect.origin.y + paperRect.size.height - 1);
       
        draw1PxStroke(context, pointA, pointB, whiteColor.CGColor);
        draw1PxStroke(context, pointB, pointC, whiteColor.CGColor);
        draw1PxStroke(context, pointC, pointD, whiteColor.CGColor);
    }

solomon
n00b
 
Posts: 3
Joined: Wed Jan 02, 2013 7:11 am
Has thanked: 0 time
Been thanked: 0 time

Re: Core Graphics Tutorial: Arcs and Paths

Postby phoward8020 » Tue Apr 23, 2013 3:42 pm

One other minor quibble: I don't see the point of making sure there's a pretty little shadow under the arc if you're just going to render it invisible with a background that's darker than the shadow. Suggest lightening the background image considerably, or simply setting the background property of the table view to light gray in IB.
phoward8020
n00b
 
Posts: 3
Joined: Tue May 01, 2012 4:43 pm
Has thanked: 0 time
Been thanked: 1 time

Re: Core Graphics Tutorial: Arcs and Paths

Postby aceboy69 » Fri Apr 26, 2013 8:44 pm

Thanks PHoward, I was having the same problem in that the line at the bottom of the cell for the curved bottom was still visible.

Must have been a typo - as I ended up copying and pasting the code in case I had missed something.

Cheers

J
aceboy69
Hacker
 
Posts: 19
Joined: Sun Sep 30, 2012 8:04 pm
Location: Brighton
Has thanked: 2 times
Been thanked: 3 times

Re: Core Graphics Tutorial: Arcs and Paths

Postby littlepotato » Fri May 03, 2013 9:04 pm

Hi,

Great set of tutorials! Just curious why you normally use the [UIColor colorWithRed:green:blue:alpha] for basic colors, instead of the built-in routines [UIColor redColor] (for example). I've run into problems on the Mac where colors created with the convenience routines aren't in the correct colorspace (for example, not in the RGB colorspace, so you get an exception when trying to pull out the RGB components). But, that doesn't seem to be an issue here. Just wondering if you would consider those two ways of getting UIColor equivalent when getting basic colors.

Thanks!
littlepotato
n00b
 
Posts: 2
Joined: Thu Jul 19, 2012 7:45 pm
Has thanked: 0 time
Been thanked: 0 time

Re: Core Graphics Tutorial: Arcs and Paths

Postby suvov » Mon May 13, 2013 11:36 am

Great tutorial, thank you.

But there is one more "little thing". If you'll try to use this code with bigger table views (ones that scroll), you might run into some cell reusability troubles. Some of cell won't redraw themselves after they were reused. Saying
Code: Select all
       
((CustomCellBackground *)cell.backgroundView).lastCell = YES;

isn't enough. You need to implement a setter in CustomCellBackground.m so it would call setNeedsDisplay (redraw) each time property being set(changed).
Code: Select all
- (void)setLastCell:(BOOL)lastCell
{
    _lastCell = lastCell;
    [self setNeedsDisplay];
}
suvov
n00b
 
Posts: 1
Joined: Mon May 13, 2013 11:28 am
Has thanked: 1 time
Been thanked: 0 time

Postby ClippingPathAsia » Tue Feb 11, 2014 5:56 am

Thanks For Share with us & Waiting for your next one

Clipping Path

ClippingPathAsia
n00b
 
Posts: 1
Joined: Tue Feb 11, 2014 5:54 am
Has thanked: 0 time
Been thanked: 0 time

Postby kirankumar » Thu Mar 13, 2014 6:19 am

Hi
kirankumar
n00b
 
Posts: 1
Joined: Thu Mar 13, 2014 6:19 am
Has thanked: 0 time
Been thanked: 0 time

Re: Core Graphics Tutorial: Arcs and Paths

Postby kirankumar » Thu Mar 13, 2014 6:28 am

Hi Everyone,

I need your help from you guys......

I have one image with different shape, if I select the image then iPhone Image gallery will be opened. When I choose any image from image gallery, that image shape has to be converted into my first image shape.

I am able to merge the images. But, i am unable to convert my selected image shape into my first image.

can you help me please.......

Code: Select all
       UIImage *bottomImage = imageCopy; //background image

    UIImage *image       = chosenImage; //foreground image
   
   
    CGSize newSize = CGSizeMake(195, 400);
    UIGraphicsBeginImageContext( newSize );
   
    // Use existing opacity as is
    [bottomImage drawInRect:CGRectMake(0,0,newSize.width,newSize.height)];
   
    // Apply supplied opacity if applicable
    [image drawInRect:CGRectMake(0,0,newSize.width,newSize.height) blendMode:kCGBlendModeNormal alpha:0.8];
   
    UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
   
    UIGraphicsEndImageContext();


This code I got from websites ...........



[img] Screen 1: Home screen

First.png
First.png (34.34 KiB) Viewed 1289 times

Screen 2: Image Gallery

Second.png
Second.png (113.6 KiB) Viewed 1289 times


Screen3: After selecting image
Third.png
Third.png (57.78 KiB) Viewed 1289 times


[/img]
kirankumar
n00b
 
Posts: 1
Joined: Thu Mar 13, 2014 6:19 am
Has thanked: 0 time
Been thanked: 0 time

Next

Return to Official Tutorials

Who is online

Users browsing this forum: Baidu [Spider] and 7 guests