我想在表格视图单元格中绘制线条,以便我可以将textfield和switch放在单个单元格中.我增加了细胞的高度.我怎样才能在细胞中划线?
我有UIView的子类,其中包含以下代码
//Get the CGContext from this view
CGContextRef context = UIGraphicsGetCurrentContext();
//Set the stroke (pen) color
CGContextSetStrokeColorWithColor(context, [UIColor redColor].CGColor);
//Set the width of the pen mark
CGContextSetLineWidth(context, 1.0);
// Draw a line
//Start at this point
CGContextMoveToPoint(context, 10.0, 30.0);
//Give instructions to the CGContext
//(move "pen" around the screen)
CGContextAddLineToPoint(context, 310.0, 30.0);
//Draw it
CGContextStrokePath(context);
Run Code Online (Sandbox Code Playgroud)
然后我有一个tableViewController与分组表格样式.在cellForRowAtIndexPath中,我有以下代码
//code to add textfield
DrawLineView *drawLine = [[DrawLineView alloc]init];
[cell addSubview:drawLine];
//code add switch
Run Code Online (Sandbox Code Playgroud)
但它没有划清界线.我不能使用2个不同的细胞.我得帮助我.这是我第一次处理iphone的图形.谢谢
下面的代码在UIView上打印一行.我只想知道我要编写的代码,以便能够在视图顶部插入图像.
import UIKit
class draw: UIView {
var line = UIBezierPath()
var line1 = UIBezierPath()
func grapher() {
line1.move(to: .init(x:0, y: bounds.height / 6))
line1.addLine(to: .init(x: bounds.width, y: bounds.height / 6))
UIColor.blue.setStroke()
line1.lineWidth = 2
line1.stroke()
}
override func draw(_ rect: CGRect) {
grapher()
}
}
Run Code Online (Sandbox Code Playgroud)