Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Separator lines drawn incorrectly in Simulator #1

Open
mleonhard opened this issue Oct 31, 2023 · 0 comments
Open

Separator lines drawn incorrectly in Simulator #1

mleonhard opened this issue Oct 31, 2023 · 0 comments

Comments

@mleonhard
Copy link
Collaborator

Separator lines in form and grouped-row-table widgets appear in the wrong places. This happens only in Simulator and only one the first page view. The separators draw properly on real iPhones and after refreshing or updating the page.

Screenshot 2023-10-30 at 10 01 49 PM

Here is the code that draws the separators:

override func draw(_ rect: CGRect) {
// TODO: Fix bug on Simulator which causes lines to be in the wrong place on first load. See Checkboxes demo page.
if let color = self.separatorColor, let ctx = UIGraphicsGetCurrentContext() {
// Draw a line left-to-right between subviews
let left = 0.0
let right = self.bounds.size.width
ctx.setLineCap(.round)
ctx.setLineWidth(CGFloat(SEPARATOR_THICKNESS))
ctx.setStrokeColor(color.cgColor)
ctx.beginPath()
if let first = self.orderedSubviews.first, let sepThickness = self.separatorThickness() {
let y = first.frame.minY - CGFloat(sepThickness / 2.0)
ctx.move(to: CGPoint(x: left, y: y))
ctx.addLine(to: CGPoint(x: right, y: y))
}
for (n, a) in self.orderedSubviews.dropLast(1).enumerated() {
let b = self.orderedSubviews[n + 1]
let y = (a.frame.maxY + b.frame.minY) / 2.0
//Self.logger.trace("draw (\(left), \(y)) -> (\(right), \(y))")
ctx.move(to: CGPoint(x: left, y: y))
ctx.addLine(to: CGPoint(x: right, y: y))
}
if let last = self.orderedSubviews.last, let sepThickness = self.separatorThickness() {
let y = last.frame.maxY + CGFloat(sepThickness / 2.0)
ctx.move(to: CGPoint(x: left, y: y))
ctx.addLine(to: CGPoint(x: right, y: y))
}
ctx.strokePath()
}
}

It seems that UIKit calls draw before laying out the views. Or it fails to update each view's frame field. I have spent many hours trying to find a workaround. If anyone has ideas, please post them here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant