数字分类支持 1-999 数字学习,按规则运行时生成词条
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
@@ -162,9 +162,14 @@ final class QuizSetupViewController: UIViewController {
|
||||
}
|
||||
|
||||
private func setupCountControl() {
|
||||
countControl.insertSegment(withTitle: "全部 \(request.words.count) 题", at: 0, animated: false)
|
||||
if request.words.count > 10 {
|
||||
countControl.insertSegment(withTitle: "随机 10 题", at: 1, animated: false)
|
||||
if request.words.count > 50 {
|
||||
countControl.insertSegment(withTitle: "随机 10 题", at: 0, animated: false)
|
||||
countControl.insertSegment(withTitle: "随机 20 题", at: 1, animated: false)
|
||||
} else {
|
||||
countControl.insertSegment(withTitle: "全部 \(request.words.count) 题", at: 0, animated: false)
|
||||
if request.words.count > 10 {
|
||||
countControl.insertSegment(withTitle: "随机 10 题", at: 1, animated: false)
|
||||
}
|
||||
}
|
||||
countControl.selectedSegmentIndex = 0
|
||||
}
|
||||
@@ -198,9 +203,15 @@ final class QuizSetupViewController: UIViewController {
|
||||
private func startQuiz() {
|
||||
guard let selectedIndex else { return }
|
||||
Haptics.selection()
|
||||
let words = countControl.selectedSegmentIndex == 0
|
||||
? request.words
|
||||
: Array(request.words.shuffled().prefix(10))
|
||||
let words: [Word]
|
||||
if request.words.count > 50 {
|
||||
let count = countControl.selectedSegmentIndex == 0 ? 10 : 20
|
||||
words = Array(request.words.shuffled().prefix(count))
|
||||
} else if countControl.selectedSegmentIndex == 0 {
|
||||
words = request.words
|
||||
} else {
|
||||
words = Array(request.words.shuffled().prefix(10))
|
||||
}
|
||||
let config = QuizConfig(mode: items[selectedIndex].mode, words: words)
|
||||
navigationController?.pushViewController(QuizViewController(config: config), animated: true)
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user