右上角更多菜单改用 UIBarButtonItem 实现
This commit is contained in:
@@ -15,14 +15,19 @@ struct FormatterView: View {
|
||||
var body: some View {
|
||||
NavigationStack {
|
||||
VStack(spacing: 0) {
|
||||
headerView
|
||||
|
||||
inputArea
|
||||
.frame(maxHeight: .infinity)
|
||||
|
||||
actionArea
|
||||
}
|
||||
.background(Color(.systemGroupedBackground).ignoresSafeArea())
|
||||
.navigationTitle("文案格式化")
|
||||
.navigationBarTitleDisplayMode(.large)
|
||||
.toolbar {
|
||||
ToolbarItem(placement: .topBarTrailing) {
|
||||
MoreMenuBarButton(text: $inputText, showCopied: $showCopied)
|
||||
}
|
||||
}
|
||||
.alert("提示", isPresented: $showEmptyAlert) {
|
||||
Button("确定", role: .cancel) {}
|
||||
} message: {
|
||||
@@ -44,42 +49,6 @@ struct FormatterView: View {
|
||||
.transition(.opacity)
|
||||
}
|
||||
}
|
||||
.navigationBarHidden(true)
|
||||
}
|
||||
}
|
||||
|
||||
private var headerView: some View {
|
||||
HStack {
|
||||
Text("文案格式化")
|
||||
.font(.largeTitle.bold())
|
||||
.foregroundStyle(.primary)
|
||||
Spacer()
|
||||
Menu {
|
||||
Button(action: copyText) {
|
||||
Label("复制", systemImage: "doc.on.doc")
|
||||
}
|
||||
.disabled(inputText.isEmpty)
|
||||
Button(role: .destructive, action: clearText) {
|
||||
Label("清除", systemImage: "xmark.circle")
|
||||
}
|
||||
.disabled(inputText.isEmpty)
|
||||
} label: {
|
||||
Image(systemName: "ellipsis")
|
||||
.font(.system(size: 20, weight: .bold))
|
||||
.foregroundStyle(.primary)
|
||||
.frame(width: 44, height: 44)
|
||||
.background(.ultraThinMaterial)
|
||||
.clipShape(Circle())
|
||||
}
|
||||
}
|
||||
.frame(maxWidth: .infinity, minHeight: 44)
|
||||
.padding(.horizontal)
|
||||
.padding(.top, 8)
|
||||
.padding(.bottom, 8)
|
||||
.background(Color(.systemGroupedBackground))
|
||||
.contentShape(Rectangle())
|
||||
.onTapGesture {
|
||||
dismissKeyboard()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -175,21 +144,6 @@ struct FormatterView: View {
|
||||
dismissKeyboard()
|
||||
}
|
||||
|
||||
private func copyText() {
|
||||
UIPasteboard.general.string = inputText
|
||||
withAnimation {
|
||||
showCopied = true
|
||||
}
|
||||
DispatchQueue.main.asyncAfter(deadline: .now() + 1.5) {
|
||||
withAnimation {
|
||||
showCopied = false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private func clearText() {
|
||||
inputText = ""
|
||||
}
|
||||
}
|
||||
|
||||
#Preview {
|
||||
|
||||
Reference in New Issue
Block a user