分隔线改为 1 物理像素发丝线,修复 UIScreen.main 弃用警告

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
2026-07-18 22:29:06 +08:00
parent 2220f4be52
commit 9893d5408a
3 changed files with 25 additions and 8 deletions
@@ -0,0 +1,23 @@
import UIKit
final class HairlineView: UIView {
private var heightConstraint: NSLayoutConstraint?
override init(frame: CGRect) {
super.init(frame: frame)
backgroundColor = .separator
translatesAutoresizingMaskIntoConstraints = false
let constraint = heightAnchor.constraint(equalToConstant: 0.5)
constraint.isActive = true
heightConstraint = constraint
}
@available(*, unavailable)
required init?(coder: NSCoder) { fatalError() }
override func didMoveToWindow() {
super.didMoveToWindow()
let scale = window?.windowScene?.screen.scale ?? 2
heightConstraint?.constant = 1.0 / scale
}
}
@@ -133,10 +133,7 @@ final class QuizResultView: UIView {
}, for: .touchUpInside) }, for: .touchUpInside)
section.addArrangedSubview(button) section.addArrangedSubview(button)
let divider = UIView() let divider = HairlineView()
divider.backgroundColor = .separator
divider.translatesAutoresizingMaskIntoConstraints = false
divider.heightAnchor.constraint(equalToConstant: 1.0 / UIScreen.main.scale).isActive = true
section.addArrangedSubview(divider) section.addArrangedSubview(divider)
} }
return section return section
@@ -106,10 +106,7 @@ final class WordDetailViewController: UIViewController {
meaningLabel.font = .preferredFont(forTextStyle: .title2) meaningLabel.font = .preferredFont(forTextStyle: .title2)
meaningLabel.numberOfLines = 0 meaningLabel.numberOfLines = 0
let divider = UIView() let divider = HairlineView()
divider.backgroundColor = .separator
divider.translatesAutoresizingMaskIntoConstraints = false
divider.heightAnchor.constraint(equalToConstant: 1.0 / UIScreen.main.scale).isActive = true
let exampleTitle = makeCaption("例句") let exampleTitle = makeCaption("例句")
let exampleLabel = UILabel() let exampleLabel = UILabel()