在Core Graphics中用相同的笔划获得不同的线条

问题描述 投票:0回答:1

我有一个 UIView 子类。

这是我重写绘制方法的方法:

let path = UIBezierPath()
path.lineWidth = 1
path.move(to: CGPoint(x: rect.minX, y: rect.minY+1))
path.addLine(to: CGPoint(x: rect.maxX, y: rect.minY+1))
UIColor.lightGray.setStroke()
path.stroke()
path.close()

但是当视图渲染时,线条似乎有所不同。 特别是,

当view.frame.height小于superview.frame.height时:

当view.frame.height大于superview.frame.height时:

无法弄清楚我做错了什么。

ios swift core-graphics
1个回答
1
投票

假设您的代码位于 draw(_ rect: CGRect) 中,请记住 rect 会有所不同。您的 path.Movepath.AddLine 调用都引用了这一点。您如何在超级视图中定位事物?自动布局还是框架?

© www.soinside.com 2019 - 2024. All rights reserved.