数字分类支持 1-999 数字学习,按规则运行时生成词条

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
2026-07-19 23:10:08 +08:00
parent cb37b809f0
commit 75b967893b
6 changed files with 167 additions and 17 deletions
@@ -126,8 +126,19 @@ final class SpellingInputView: UIView, UITextFieldDelegate {
private func rebuildBoxes() {
stack.arrangedSubviews.forEach { $0.removeFromSuperview() }
let count = CGFloat(max(chars.count, 1))
let available = (window?.screen.bounds.width ?? 390) - 32
var spacing: CGFloat = 6
var boxWidth = (available - spacing * (count - 1)) / count
if boxWidth < 16 {
spacing = 3
boxWidth = (available - spacing * (count - 1)) / count
}
boxWidth = min(36, boxWidth)
stack.spacing = spacing
let fontSize = min(22, max(12, boxWidth * 0.62))
boxViews = chars.enumerated().map { index, ch in
let box = makeBox()
let box = makeBox(fontSize: fontSize)
box.tag = index
if ch != "_", let label = box.viewWithTag(100) as? UILabel {
label.text = ch.uppercased()
@@ -136,7 +147,7 @@ final class SpellingInputView: UIView, UITextFieldDelegate {
box.addGestureRecognizer(UITapGestureRecognizer(target: self, action: #selector(boxTapped(_:))))
stack.addArrangedSubview(box)
NSLayoutConstraint.activate([
box.widthAnchor.constraint(equalToConstant: 36),
box.widthAnchor.constraint(equalToConstant: boxWidth),
box.heightAnchor.constraint(equalToConstant: 44)
])
return box
@@ -158,7 +169,7 @@ final class SpellingInputView: UIView, UITextFieldDelegate {
activate()
}
private func makeBox() -> UIView {
private func makeBox(fontSize: CGFloat) -> UIView {
let box = UIView()
box.backgroundColor = .quaternarySystemFill.withAlphaComponent(0.15)
box.layer.cornerRadius = 8
@@ -166,8 +177,7 @@ final class SpellingInputView: UIView, UITextFieldDelegate {
box.layer.borderColor = UIColor.separator.cgColor
let label = UILabel()
label.font = .preferredFont(forTextStyle: .title2)
label.font = .systemFont(ofSize: label.font.pointSize, weight: .bold)
label.font = .systemFont(ofSize: fontSize, weight: .bold)
label.isHidden = true
label.tag = 100
box.addSubview(label)