Xcode iphone touch dotted painting

In every body I am French, so excuse me for my English. My problem is that I want to draw a bitmap on the iphone like this, -----------, not a line, but a draw. I have:

CGContextSetLineCap(UIGraphicsGetCurrentContext(), kCGLineCapRound); //kCGLineCapSquare, kCGLineCapButt, kCGLineCapRound CGContextSetLineWidth(UIGraphicsGetCurrentContext(), 10.0); // for size CGContextSetRGBStrokeColor(UIGraphicsGetCurrentContext(), 0.0, 1.0, 0.0, 1.0); //values for R, G, B, and Alpha CGContextBeginPath(UIGraphicsGetCurrentContext()); CGContextMoveToPoint(UIGraphicsGetCurrentContext(), lastPoint.x, lastPoint.y); CGContextAddLineToPoint(UIGraphicsGetCurrentContext(), currentPoint.x, currentPoint.y); CGContextStrokePath(UIGraphicsGetCurrentContext()); drawImage.image = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext(); 

What is the code for "dotted".

+4
source share
3 answers

CGContextSetLineDash

http://developer.apple.com/library/mac/#documentation/GraphicsImaging/Reference/CGContext/Reference/reference.html%23//apple_ref/c/func/CGContextSetLineDash

Example:

 CGFloat dashes[] = { 1, 1 }; CGContextSetLineDash( context, 0.0, dashes, 2 ); 

Or just open the QuartzDemo sample in Xcode and look at the QuartzLines.m file (QuartzDashView class).

You really have to read the documentation (see the link mentioned).

+4
source

Your problem is that you did not refer to the context before this: CGContextSetLineDash (context, 0.0, dash, 2);

You need to do this: CGContextRef context = UIGraphicsGetCurrentContext(); then replace all your UIGraphicsGetC ... calls with context to speed it up.

The Deitel iPhone App-Driven Approach book has an example of this.

feud

+2
source

Check out the awesome line properties page! https://horseshoe7.wordpress.com/2014/07/16/core-graphics-line-drawing-explained/

According to the above page, the code for a dot string similar to (...) is given

 // should CGContextSetLineCap(context, kCGLineCapRound); // please see the role of line properties why the first should be 0 and the second should be the doulbe of the given line width CGFloat dash[] = {0, lineWidth*2}; // the second value (0) means the span between sets of dot patterns defined by dash array CGContextSetLineDash(context, 0, dash, 2); 
0
source

Source: https://habr.com/ru/post/1340456/


All Articles