0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

【SwiftUI】角丸ボタン枠線ボタンのサンプル

Posted at

個人的に使いやすいシンプルなボタンのサンプルです。
未来の自分のために残しておこうと思います。

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)
        }
    }
}

スクリーンショット 2023-02-12 18.17.52.png

ボタンタップ後の処理も渡せるので使いやすいかと思います。
大きさや、カラーなどはお好みで変更すれば良いと思います!
以上です。

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?