В настоящее время я рисую линию, используя Core Graphics. Это действительно голые и простые.
- (void)drawRect:(CGRect)rect {
CGContextRef c = UIGraphicsGetCurrentContext();
CGFloat red[4] = {1.0f, 0.0f, 0.0f, 1.0f};
CGContextSetStrokeColor(c, red);
CGContextBeginPath(c);
CGContextMoveToPoint(c, 5.0f, 5.0f);
CGContextAddLineToPoint(c, 300.0f, 600.0f);
CGContextSetLineWidth(c, 25);
CGContextSetLineCap(c, kCGLineCapRound);
CGContextStrokePath(c);
}
Это хорошо работает. Допустим, мы хотели нарисовать линию нестандартного стиля. Скажем, мы хотели подражать стилю мелка, например. И чтобы дизайнер передал ваши мелки в стиле изображений: http://imgur.com/a/N40ig
Чтобы добиться этого эффекта, я думаю, мне нужно сделать что-то вроде этого:
Создание специальных цветных версий crayonImage1-crayonImage4
Каждый раз, когда вы добавляете строку в строку, вы используете один из изображений crayonImage
Вы чередуете crayonImages каждый раз, когда рисуете точку.
Шаг 1 имеет смысл. Я могу использовать следующий метод:
- (UIImage *)image:(UIImage *)img withColor:(UIColor *)color {
// begin a new image context, to draw our colored image onto
UIGraphicsBeginImageContext(img.size);
// get a reference to that context we created
CGContextRef context = UIGraphicsGetCurrentContext();
// set the fill color
[color setFill];
// translate/flip the graphics context (for transforming from CG* coords to UI* coords
CGContextTranslateCTM(context, 0, img.size.height);
CGContextScaleCTM(context, 1.0, -1.0);
// set the blend mode to color burn, and the original image
CGContextSetBlendMode(context, kCGBlendModeColorBurn);
CGRect rect = CGRectMake(0, 0, img.size.width, img.size.height);
CGContextDrawImage(context, rect, img.CGImage);
// set a mask that matches the shape of the image, then draw (color burn) a colored rectangle
CGContextClipToMask(context, rect, img.CGImage);
CGContextAddRect(context, rect);
CGContextDrawPath(context,kCGPathFill);
// generate a new UIImage from the graphics context we drew onto
UIImage *coloredImg = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
//return the color-burned image
return coloredImg;
}
Я не уверен, как я могу выполнить шаги 2 и 3. Есть ли в CoreGraphics API для установки изображения в качестве точки линии? Если так, что это и как я могу использовать это?
Заранее спасибо,
-Давид