You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
70 lines
1.9 KiB
70 lines
1.9 KiB
import SwiftUI
|
|
|
|
// MARK: - 输入提示组件
|
|
struct InputHintView: View {
|
|
let hint: String
|
|
let icon: String
|
|
let color: Color
|
|
|
|
init(hint: String, icon: String = "info.circle", color: Color = .blue) {
|
|
self.hint = hint
|
|
self.icon = icon
|
|
self.color = color
|
|
}
|
|
|
|
var body: some View {
|
|
VStack(spacing: 12) {
|
|
HStack {
|
|
Image(systemName: icon)
|
|
.font(.caption)
|
|
.foregroundColor(color)
|
|
|
|
Text("输入提示")
|
|
.font(.caption)
|
|
.foregroundColor(.primary)
|
|
|
|
Spacer()
|
|
}
|
|
|
|
Text(hint)
|
|
.font(.caption)
|
|
.foregroundColor(.secondary)
|
|
.lineLimit(nil)
|
|
}
|
|
.padding(.horizontal, 12)
|
|
.padding(.vertical, 8)
|
|
.background(
|
|
RoundedRectangle(cornerRadius: 8)
|
|
.fill(color.opacity(0.1))
|
|
)
|
|
}
|
|
}
|
|
|
|
// MARK: - 预定义的提示样式
|
|
extension InputHintView {
|
|
static func info(hint: String) -> InputHintView {
|
|
InputHintView(hint: hint, icon: "info.circle", color: .blue)
|
|
}
|
|
|
|
static func warning(hint: String) -> InputHintView {
|
|
InputHintView(hint: hint, icon: "exclamationmark.triangle", color: .orange)
|
|
}
|
|
|
|
static func success(hint: String) -> InputHintView {
|
|
InputHintView(hint: hint, icon: "checkmark.circle", color: .green)
|
|
}
|
|
|
|
static func error(hint: String) -> InputHintView {
|
|
InputHintView(hint: hint, icon: "xmark.circle", color: .red)
|
|
}
|
|
}
|
|
|
|
#Preview {
|
|
VStack(spacing: 16) {
|
|
InputHintView.info(hint: "这是一个信息提示")
|
|
InputHintView.warning(hint: "这是一个警告提示")
|
|
InputHintView.success(hint: "这是一个成功提示")
|
|
InputHintView.error(hint: "这是一个错误提示")
|
|
}
|
|
.padding()
|
|
} |