個人的に使いやすいシンプルなボタンのサンプルです。
未来の自分のために残しておこうと思います。
Xcode Version 14.2
WhiteButton.swift
import SwiftUI
struct WhiteButton: View {
private var text : String
var onTapped: () -> Void
init(text: String,onTapped: @escaping () -> Void) {
self.text = text
self.onTapped = onTapped
}
var body: some View {
Button(action: {
onTapped()
}) {
Text(text)
.lineLimit(1)
.font(.system(size: 15, weight: .regular, design: .default))
.foregroundColor(Color.secondaryColorBlue)
.frame(width: 100,height: 45)
.background( Color.white)
.foregroundColor(Color.white)
.overlay(RoundedRectangle(cornerRadius: 5).stroke(Color.mainBlue, lineWidth: 1))
.cornerRadius(5)
}
}
}
ボタンタップ後の処理も渡せるので使いやすいかと思います。
大きさや、カラーなどはお好みで変更すれば良いと思います!
以上です。