Skip to content

Separator lines drawn incorrectly in Simulator #1

@mleonhard

Description

@mleonhard

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions