Coloring a UIBezierPath - iphone

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.

Related

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

Stroking a CGPath with a gradient?

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.

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?

Core-Plot highlighting a single candlestick bar

I have a CPTTradingRangePlot with a CPTTradingRangePlotStyleCandleStick style.
I'm looking for a way to highlight a specific (or a few) candlesticks with a different fill color (or a glow, or something), but I can't find a way to access individual candlesticks in a similar way that a CPTBarPlot has with -(CPTFill *)barFillForBarPlot:(CPTBarPlot *)barPlot recordIndex:(NSUInteger)index;
Am I missing something here?
Can I somehow maybe access a specific candlestick after the data load, and then change the fill color?
I was also thinking about adding an Annotation Layer, and maybe draw a circle around the specific candlestick(s), but I don't want to use an image, since it will get stretched and pixelated when I'll adjust it's size.
Is there any way to draw a vector-based shape as an annotation around the candlesticks?
Thanks for any help!
You can put a request for that feature on the Core Plot issue tracker. In the meantime, you can achieve the same look by using more than one plot, one for each different style.

how to set different brush patterns iphone

I set brush pattern using CGContext and Bezierpath on UIImageView.
Is this a good approach?
Do we have any other best practices to set brush pattern, to create different paint brush pattern.
Does anybody have different design pattern that I can use when implementing my brush?
Yes, it's fine if that's what you want to do. All a "brush" means in this context is how you want to stroke a line. If you're just trying to set the stroke pattern for a bezier path on some UIImageView then yes, it sounds like what you're doing is appropriate.
Now, depending on what your end goal is, there may be different ways to approach it. Your method might have complications when interacting with the higher level drawing in UIKit. Since you asked this 7 months ago though, I'm hoping you already figured it out.
If you are using bezierpath then you can use patternImage code in bezierpath. If you are using CGContext then adjust your strokewidth and use kcglinecap methods to get different points.
In bezierpath you can also use dashpattern so you can draw dash lines.