我想将带有以编程方式绘制的线条作为背景图案的 UIView 添加到 UITextView 字段(根据 UITextView 中的错字,textview 字段应该看起来有点像具有适当行高的衬纸)。
这是线条的 UIView 绘制代码当前看起来像一些固定值。
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);
我发现实际上可以将背景图像作为 UIColor 分配给 UITextview(在本例中为“viewLogNote”)。
[[self viewLogNote]setBackgroundColor:[UIColor colorWithPatternImage:[UIImage imageNamed: @"UITextField_Background"]]];
有没有办法用自定义绘图做类似的事情?