If you only have strings, you can work with the function below. Otherwise, I would recommend walking the entire length of your line and creating a square of the line width at a certain distance and checking if it is in your view. Example. If you have a line from x0y0 to x7y0. You need to go to x1y0 to create a square of your drawing line size (in this example 15) and see if this screen overlaps your screen. Then go to x2y0 and so on. The advantage is that it will even work with Bezier curves (some information on the wiki, how Bezier will work).
// EDIT: (made a small bezier check function, should work, but not tested). And I don't think its more efficient performance for checking every line before drawing:
- (void)bezierWithStart:(CGPoint)start cp1:(CGPoint)cp1 cp2:(CGPoint)cp2 end:(CGPoint)end withWidth:(float)wid { for (float i = 0.0; i<=1.0; i+=0.05) {
// EDIT end
But now let's move on to a simple line function:
- (void)testLine:(CGPoint)fp toSecond:(CGPoint)sp withWidth:(float)wid { float xratio = sp.x - fp.x; float yratio = sp.y - fp.y; double a = sqrt(((wid*wid)*(xratio*xratio))/((yratio*yratio)+(xratio*xratio))); a/=2;
you will get 4 points. 2 lines, one on top and one below the original line, half the size of your width. The calculation behind is getting the direction of the draw and for that the difference is with the original line. But for those who want to penetrate into it, this is my preliminary calculation:

user207616
source share