From 152dcd9aacfe807c97a75cb9f38c863db5603518 Mon Sep 17 00:00:00 2001 From: fish Date: Sun, 19 Jul 2026 21:48:20 +0800 Subject: [PATCH] =?UTF-8?q?=E8=AF=A6=E6=83=85=E9=A1=B5=E9=87=8A=E4=B9=89?= =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E6=90=9C=E7=B4=A2=E6=8C=89=E9=92=AE=EF=BC=8C?= =?UTF-8?q?=E5=BA=94=E7=94=A8=E5=86=85=E6=89=93=E5=BC=80=20Google=20?= =?UTF-8?q?=E6=90=9C=E7=B4=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Claude Opus 4.7 --- .../Views/WordDetailViewController.swift | 24 ++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/LearnEnglish/LearnEnglish/Views/WordDetailViewController.swift b/LearnEnglish/LearnEnglish/Views/WordDetailViewController.swift index 149186a..ceefae9 100644 --- a/LearnEnglish/LearnEnglish/Views/WordDetailViewController.swift +++ b/LearnEnglish/LearnEnglish/Views/WordDetailViewController.swift @@ -1,3 +1,4 @@ +import SafariServices import UIKit final class WordDetailViewController: UIViewController { @@ -125,6 +126,20 @@ final class WordDetailViewController: UIViewController { meaningLabel.font = .preferredFont(forTextStyle: .title2) meaningLabel.numberOfLines = 0 + var searchConfig = UIButton.Configuration.plain() + searchConfig.baseForegroundColor = Theme.Color.accent + searchConfig.image = UIImage(systemName: "magnifyingglass", + withConfiguration: UIImage.SymbolConfiguration(pointSize: 15, weight: .medium)) + let searchButton = UIButton(type: .system) + searchButton.configuration = searchConfig + searchButton.addAction(UIAction { [weak self] _ in self?.searchMeaning() }, for: .touchUpInside) + searchButton.setContentHuggingPriority(.required, for: .horizontal) + + let meaningRow = UIStackView(arrangedSubviews: [meaningLabel, searchButton]) + meaningRow.axis = .horizontal + meaningRow.alignment = .top + meaningRow.spacing = 8 + let divider = HairlineView() let exampleTitle = makeCaption("例句") @@ -154,7 +169,7 @@ final class WordDetailViewController: UIViewController { exampleRow.alignment = .top exampleRow.spacing = 8 - let stack = UIStackView(arrangedSubviews: [meaningTitle, meaningLabel, divider, exampleTitle, exampleRow]) + let stack = UIStackView(arrangedSubviews: [meaningTitle, meaningRow, divider, exampleTitle, exampleRow]) stack.axis = .vertical stack.spacing = 16 stack.setCustomSpacing(6, after: meaningTitle) @@ -171,6 +186,13 @@ final class WordDetailViewController: UIViewController { return card } + private func searchMeaning() { + Haptics.selection() + guard let query = word.meaning.addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed), + let url = URL(string: "https://www.google.com/search?q=\(query)") else { return } + present(SFSafariViewController(url: url), animated: true) + } + private func makeCaption(_ text: String) -> UILabel { let label = UILabel() label.text = text