fill UIBezierPath but keep path clear - objective-c

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...

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.

how to draw UIButton with tint color and rounder from single side only

I wanna draw a UIButton filled with a red tint color or some color else presented by rgb and only the upper edges are rounded.
some people answer me to get an image to do that but every time i want to change it i have to bring new image and replace it, I wanna ask can i do it from code without get an image.
There is no direct way. Only way to achieve this to create a segment control and keep only a single segment in that.
See this post for detailed implementation,
Update:
If you want to round only two corners check Round two corners in UIView or Just two rounded corners? as mentioned in rdurand's comment. Since segment control is a subview of UIView, this should work.
You can draw the rounded corners using NSBezierPath s bezierPathWithRoundedRect:xRadius:yRadius: method. And then draw over it with another bezier path. Or you could just define a custom bezier path using moveToPoint: lineToPoint: and curveToPoint:controlPoint1:controlPoint2:
Take a look at this:
https://developer.apple.com/library/mac/#documentation/Cocoa/Reference/ApplicationKit/Classes/NSBezierPath_Class/Reference/Reference.html

colorWithPatternImage Selected image for setStroke drawing is not whole screen

I am drawing on screen with fingers.
The problem is stroke I set. I am setting the stroke as a pattern of an image which means instead of using colors I am using an image and painting with that image like a texture.
NSString *path = [[NSBundle mainBundle] pathForResource:[NSString stringWithFormat:#"pattern"] ofType:#"png"];
[[UIColor colorWithPatternImage:[UIImage imageWithContentsOfFile:path]] setStroke]];
The problem is I am getting the image on the screen when I draw and it is not drawing whole screen with the pattern I use, only a portion of it till I get the image of my pattern.
In another word, the pattern does not completely paint the area I want to paint. Edges of the area stays blank and not I can not make that edge area get painted with the pattern of the image.
How can I extend the size of my pattern image or set my stroke to fill whole screen?
Let me paraphrase my question and ask it in a better way:
Even I decrease the image size that I use as my pattern, that does not make any difference and I am not able to paint the area completely.
How can I paint the whole area without leaving the edges blank and not painted with the pattern I use?
Thanks

Difference between stroke and fill?

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.