Avoid division by 0

This commit is contained in:
Jed Fox 2022-12-15 07:42:10 -05:00
parent cc4df41fbb
commit dccfb4e831
No known key found for this signature in database
GPG Key ID: 0B61D18EA54B47E1
2 changed files with 21 additions and 3 deletions

View File

@ -0,0 +1,18 @@
//
// UIScreen.swift
//
//
// Created by Jed Fox on 2022-12-15.
//
import UIKit
extension UIScreen {
public var pixelSize: CGFloat {
if scale > 0 {
return 1 / scale
}
// should never happen but just in case
return 1
}
}

View File

@ -184,8 +184,8 @@ public final class StatusCardControl: UIControl {
super.didMoveToWindow() super.didMoveToWindow()
if let window = window { if let window = window {
layer.borderWidth = 1 / window.screen.scale layer.borderWidth = window.screen.pixelSize
dividerConstraint?.constant = 1 / window.screen.scale dividerConstraint?.constant = 1 / window.screen.pixelSize
} }
} }
@ -196,7 +196,7 @@ public final class StatusCardControl: UIControl {
NSLayoutConstraint.deactivate(layoutConstraints) NSLayoutConstraint.deactivate(layoutConstraints)
dividerConstraint?.deactivate() dividerConstraint?.deactivate()
let pixelSize = 1 / (window?.screen.scale ?? 1) let pixelSize = 1 / (window?.screen.pixelSize ?? 1)
switch layout { switch layout {
case .large(let aspectRatio): case .large(let aspectRatio):
containerStackView.alignment = .fill containerStackView.alignment = .fill