Stroking a CGPath with a gradient? - iphone

I've been looking into this for a while now, and as a beginner, I can't seem to get it done. What I want to do is take a simple gradient, and use it to stroke a CGPath. I tried using CGContextSetStokePattern with a PNG the width of the line and one pixel tall containing my desired gradient, but this tiles the pattern, whilst I'd rather have it drawn along the path like a brush. Closest thing I can think of would be the Styler from Pokémon Ranger.
Essentially, I'd like my line to start out one color in the middle and move towards another at the edges. There's probably a simple way of doing this, but I cannot for the life of me figure out how.
Much thanks to anyone who can help me. :)

There's no built-in support for stroking a path in that way.
You could try to fake it by stroking the path multiple times, with each stroke having a narrow line width than the prior stroke and a different color, and maybe different shadow settings too. Of course stroking it repeatedly will take longer than stroking it once.

Related

Unity3D - Flexible border with changeable line color

I need to create random-shaped (could be rectangular or circular) border for my UI, which can change its size, thickness and color of line. What approach to choose?
9-slice scaling texture is not an option since I need to change colors of line and background dynamically.
Write my own shader - I tried to dive into it and I think I'm not up to it right now. Also I was unable to find shader like this made by someone else.
Create border as a mesh, which is probably expensive in GPU resources.
This must be very common task, I really need advice from experienced unitist. How would you do this?
Thanks.

SpriteKit - Draw Bezier Curve Gradually

I'm working on an iOS educational where kids are drawing letters. The game mechanism is pretty simple and works OK. What I want to do is to show a drawing progress by turning the elapsed part into green thick line. See the image:
There are couple of solution I have in mind.
Mask over hidden path which transforms according to users touch position
Creating a new path on touchesMoved: by taking the original and adding a point to the user touch position, then stripping the rest
What would you choose or is there some better solution?
Note: I want to draw the green path precisely as the dashed one. By just drawing a path following the user movement would result in ugly line.
Thanks.
I would say your choice depends on whether the dashed line is also drawn (or drawable in all of its parts) with bezier curves.
If the dashed line is an image you show, probably solution 1 with an also drawn thick line and an adapted mask is easiest to do.
If the dashed line is already drawn as a bezier curve (or drawn by drawing several connected bezier curves), then solution 2 seems best to me. The tricky part would be to ensure you exactly follow the dashed line in this case (but I suppose you figured that already :-).

How to draw custom line on MKMapview?

I've been searching for a way to draw a custom line, but the only help I can find is how to draw lines with an UIColor.
I want to draw a straight line but not just with a color. I want the appearance of the line to be customizable.
(So right now I can draw lines between 2 points, but not the line I want)
The line I want got straight 45 degree lines on it, and it's grey and black.
Anybody can help?
The line looks like this, I'm also thinking that I could stretch this image, but if I stretch it, it will look kinda weird.
Why don't you add image then? I'm new developer so I don't know other way to do it. Only OpenGL with texturing, but there is no need to use openGL. So my suggestion is to add image.
Sound like what your looking for is the MKPolylineView Class. You assign it a polyline which contains the points in your line. Since the polyline view is an MKOverlayPathView you can set the stroke and fill colors.
Since it's also a UIView subclass you can manipulate the appearance even further by grabing the views layer property and adding gradients, shadows, masks, etc.
Is there a specific effect that you're trying to achieve?

Coloring a UIBezierPath

I was wondering how this can be accomplished.
I am looking to color part of a UIBezierPath, not the whole thing.
For example, I'm interested in coloring from the beginning to middle of the path a different color.
I think you'll have to create separate paths, then draw them independently.

Add shading to clipped UIView

I'm creating an iphone application. I have this UIView whose content is clipped with a path. I want to add shading and/or shadow to it. What's the best way to do this? For shadow, I tried CGContextSetShadow() but it doesn't seem to have an effect (perhaps it's drawing outside the shown region?) . How about shading? I want it to appear along the path. What's the best way to go about it? Is it to create another narrow clip strip along the original clipping path (if it's possible to have two clip path... ) Or does this need to be done in another CALayer? I am not even sure what that is yet.
You can't add shadows to layers which are clipped or masked. The way I would do this is use two CALayers, one for the clipped content and place this inside another for the shadow which isn't clipped.