I’d like to add UIView with programmatically drawn lines as a background pattern to a UITextView field (The textview field should look a bit like a lined piece of paper with proper line height according to the typo in the UITextView).
Here’s what the UIView draw code of the lines currently look like with some fixed values.
for (int i = 0; i < 4; i++) {
CGContextMoveToPoint(context, 80.0, (215.0+i*21.0));
CGContextAddLineToPoint(context, 310.0, (215.0+i*21.0));
}
CGContextSetShouldAntialias(context, false);
CGContextStrokePath(context);
I found that it is actually possible to assign a backgound image as UIColor to a UITextview (in this case “viewLogNote”).
[[self viewLogNote]setBackgroundColor:[UIColor colorWithPatternImage:[UIImage imageNamed: @"UITextField_Background"]]];
Is there a way to do something similar with the custom drawing?
Lets assume your UIView is called view and UITextView is called textView. Try this and let me know if it works: