Difference between stroke and fill? - iphone-sdk-3.0

What's the difference between Stroke and Fill drawing in graphics context (iPhone SDK)

Stroke is line drawing, Fill is "colouring in" (for want of a better term).
So in the case of a shape (like a circle), the stroke is the border (circumference) and the fill is the body (interior).

Stroke only draws stuff on the border of the path.
Fill only draws stuff in the interior of the path.

Related

Add Clipping Mask on Pen Stroke Path

I have a text object with a white pen stroke running through it. I want to make that path a clipping mask, so that it would be a transparency instead of a white line, so that I can put it on any background.
When I do a Clipping Mask however, this is what I get:
My pen stroke is the top-most layer as well.
Assistance plz.
First you need to expand the stroke so it is a closed path: Object>expand
Next fill the new shape black place it where you want it. Copy it and delete it.
Now select the text object and create a new opacity mask. Paste your clipping shape in the opacity mask. uncheck clip.

draw a rectangle then draw a line clipped to that rectangle

Can someone explain the concepts/actions required to do the following:
On my stage I add a myShape then draw a rectangle using the its .graphics. Then I want to draw lines on that rectangle but have them clip automatically to the rectangle i.e. so they don't leak onto the rest of the stage.
It looks as if I could do this using a mask but I am wondering if there is something much simpler I am not understanding.

fill UIBezierPath but keep path clear

Can't find solution for fill closed UIBezierPath with some color and some width, but keep the path line transparent.
[[UIColor clearColor] setStroke] does not work.
What i have:
What i want:
Shared line of two rectangles have same coordinates, that's why i need some shift when i draw them.
If what you are trying to do is erase everything within the thick outline of a path, use CGContextReplacePathWithStrokedPath to convert the stroke to a path. Then fill it with a clear blend mode, thus erasing the drawing along the thick path. Alternatively, just stroke the path, again using a clear blend mode.
In this drawing, the thick yellow ellipse is not stroked or filled yellow; the ellipse is clear, and the yellow is the view behind, seen through the red rectangle. In other words, the ellipse erases an elliptical shape through the red rectangle.
Here's the code that drew the ellipse:
CGContextAddEllipseInRect(con, CGRectMake(100,100,200,50))
CGContextSetLineWidth(con, 10)
CGContextSetBlendMode(con, kCGBlendModeClear)
CGContextReplacePathWithStrokedPath(con)
CGContextFillPath(con)
Or you could do it this way:
CGContextAddEllipseInRect(con, CGRectMake(100,100,200,50))
CGContextSetLineWidth(con, 10)
CGContextSetBlendMode(con, kCGBlendModeClear)
CGContextStrokePath(con)
stroking with [UIColor clearColor] is not the same thing as taking an eraser to the fill you've already done, it is just drawing over it with a pen with transparent ink.
You could make a second path with pathByStrokingPath and then use an EOClip to 'mask' this area from your fill, or you can just stroke your path with whatever backgroundColor is behind...

How to create letterpress effect?

I'm looking to implement something like the famous "letterpress" effect in my application. Here's what I'm talking about: (just a quick example made in PShop)
As you can see, it looks like it's pressed into the background. I wonder if it's possible to do something like this on the Mac dynamically. Is there a way? Thanks!
You can do the gradient fill portion of the text using the code I provide in this answer. Check the coordinate space first, because I described that for the iPhone, which has an inverted Y axis when compared to the Mac's normal Quartz coordinates.
The text is first used to create a clipping path, and the gradient is drawn within that path.
As far as the internal shadow, you might be able to draw this after the gradient is drawn by using CGContextSetShadowWithColor() with an appropriate downward offset and black color, then drawing the text again using just the stroke of the text. deanWombourne has some sample code for a similar task in his answer here.
Draw the text with a normal font to create a black and white bitmap of the text.
Draw another image that is is the same size and completely filled with the gray-to-white gradient you have above.
Create a completely white image with the same size as your other images.
Draw your back and white text image (1) onto the white image (3) with NSCompositeDestinationOut.
This gives you a white image with your text cut out.
Draw the white image with the text cut out on top of the gradient image and apply a shadow while drawing.

How do I make a triangle space with text written for the iPhone?

I want to draw a triangle and elide text in the shape. I can restrict the triangle to an equilateral triangle and a fixed orientation ('upside down' or 'upside up'). Then I want to insert arbitrary text in the triangle such that the eliding is on word boundaries and not clipped.
Any simple algorithms? What methods are available in Objective-C?
I am thinking of calculating lines of rectangles of 'font height' and width bounded by the top-side as it intersects the triangle's sides. Then draw-text of the remaining text into each rectangle until done.
Wait for the 3.2 SDK...