单词列表卡片增加学习按钮,点击跳转拼写练习

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
2026-07-20 08:31:53 +08:00
parent a3c7d197b1
commit 09800c5b17
2 changed files with 19 additions and 1 deletions
@@ -5,10 +5,12 @@ final class WordCardCell: UITableViewCell {
private let wordLabel = UILabel() private let wordLabel = UILabel()
private let phoneticLabel = UILabel() private let phoneticLabel = UILabel()
private let meaningLabel = UILabel() private let meaningLabel = UILabel()
private let learnButton = UIButton(type: .system)
private let speakerButton = UIButton(type: .system) private let speakerButton = UIButton(type: .system)
private var word: Word? private var word: Word?
var onSpeak: ((Word) -> Void)? var onSpeak: ((Word) -> Void)?
var onLearn: ((Word) -> Void)?
var zoomSourceView: UIView { cardView } var zoomSourceView: UIView { cardView }
@@ -39,6 +41,15 @@ final class WordCardCell: UITableViewCell {
textStack.axis = .vertical textStack.axis = .vertical
textStack.spacing = 8 textStack.spacing = 8
learnButton.setImage(UIImage(systemName: "book",
withConfiguration: UIImage.SymbolConfiguration(pointSize: 15, weight: .medium)),
for: .normal)
learnButton.tintColor = Theme.Color.accent
learnButton.addAction(UIAction { [weak self] _ in
guard let self, let word else { return }
onLearn?(word)
}, for: .touchUpInside)
speakerButton.tintColor = Theme.Color.accent speakerButton.tintColor = Theme.Color.accent
speakerButton.addAction(UIAction { [weak self] _ in speakerButton.addAction(UIAction { [weak self] _ in
guard let self, let word else { return } guard let self, let word else { return }
@@ -46,7 +57,7 @@ final class WordCardCell: UITableViewCell {
}, for: .touchUpInside) }, for: .touchUpInside)
speakerButton.setContentHuggingPriority(.required, for: .horizontal) speakerButton.setContentHuggingPriority(.required, for: .horizontal)
let row = UIStackView(arrangedSubviews: [textStack, speakerButton]) let row = UIStackView(arrangedSubviews: [textStack, learnButton, speakerButton])
row.axis = .horizontal row.axis = .horizontal
row.alignment = .center row.alignment = .center
row.spacing = 8 row.spacing = 8
@@ -57,6 +68,8 @@ final class WordCardCell: UITableViewCell {
row.leadingAnchor.constraint(equalTo: cardView.leadingAnchor, constant: 14), row.leadingAnchor.constraint(equalTo: cardView.leadingAnchor, constant: 14),
row.trailingAnchor.constraint(equalTo: cardView.trailingAnchor, constant: -8), row.trailingAnchor.constraint(equalTo: cardView.trailingAnchor, constant: -8),
row.bottomAnchor.constraint(equalTo: cardView.bottomAnchor, constant: -10), row.bottomAnchor.constraint(equalTo: cardView.bottomAnchor, constant: -10),
learnButton.widthAnchor.constraint(equalToConstant: 44),
learnButton.heightAnchor.constraint(equalToConstant: 44),
speakerButton.widthAnchor.constraint(equalToConstant: 44), speakerButton.widthAnchor.constraint(equalToConstant: 44),
speakerButton.heightAnchor.constraint(equalToConstant: 44) speakerButton.heightAnchor.constraint(equalToConstant: 44)
]) ])
@@ -148,6 +148,11 @@ extension WordListViewController: UITableViewDataSource, UITableViewDelegate {
cell.onSpeak = { word in cell.onSpeak = { word in
SpeechService.shared.speak(word.word) SpeechService.shared.speak(word.word)
} }
cell.onLearn = { [weak self] word in
guard let self else { return }
let config = QuizConfig(mode: .spelling, words: [word], isStudyMode: true)
navigationController?.pushViewController(QuizViewController(config: config), animated: true)
}
return cell return cell
} }