I'm trying to draw a rough line, a normal straight line just looks odd in my app. I'm using a fun font etc and a straight line just doesn't work.
When I say rough, I mean I want to add some noise or texture to it.
I've tried adding an image as a texture but the options I've tried use a uniform tiled approach which looks too georometricly sound.
I need to either add a scatter effect to draw my texture image roughly in the shape of a line or some sort of random approach to add noise.
I know I could just draw a rough line in a imaging app and use that, but I'm not sure about colouring and size at this stage and I'd rather use something dynamic.
I've spend far too long on this issue and a lot if time googling and can't find anything I can use, so if you have a solution please provide or point me at some example code.
Thanks.
This is the best solution I've found, but it's too uniform...
#import "DrawTexturedLine.h"
@implementation DrawTexturedLine
- (void)drawRect:(CGRect)rect
{
CGContextRef context = UIGraphicsGetCurrentContext();
[self patternMake2:rect context:context];
}
void pattern2Callback (void *info, CGContextRef context) {
UIImage *image = [UIImage imageNamed:@"particle.png"];
CGImageRef imageRef = [image CGImage];
CGContextDrawImage(context, CGRectMake(0, 0, 50, 25), imageRef);
}
- (void)patternMake2:(CGRect)rect context:(CGContextRef)context
{
static const CGPatternCallbacks callbacks = { 0, &pattern2Callback, NULL };
CGColorSpaceRef patternSpace = CGColorSpaceCreatePattern(NULL);
CGContextSetFillColorSpace(context, patternSpace);
CGColorSpaceRelease(patternSpace);
CGSize patternSize = CGSizeMake(25/2.0, 25);
CGPatternRef pattern = CGPatternCreate(NULL, self.bounds,
CGAffineTransformIdentity, patternSize.width, patternSize.height,
kCGPathFillStroke, true, &callbacks);
CGFloat alpha = 1;
CGContextSetFillPattern(context, pattern, &alpha);
CGPatternRelease(pattern);
CGContextFillRect(context, rect);
//CGContextRestoreGState(context);
}
@end