見出し画像

SwiftUIでいこう! -その他いろいろ(new!)-2

badge(Tab and List) バッジをつけます。

Tabの場合

Text("Your home screen here")
                .tabItem {
                    Label("Home", systemImage: "house")
                }
                .badge(5)

リストの場合は

List {
    Text("Wi-Fi")
        .badge("LAN Solo")

    Text("Bluetooth")
        .badge("On")
}


LocationButton

必要なライブラリの"import"

import CoreLocation
import CoreLocationUI

クラスを作ってロケーションが使えるようにしておきます。

そしてボタンを押して取得、共有できるようにします。

      LocationButton {
                locationManager.requestLocation()
            }
            .frame(height: 44)
            .padding()


select text

このモディファイアはコピー、シェアを".enabled"をつけることで可能とします。

VStack(spacing: 50) {
            Text("You can't touch this")
                .textSelection(.enabled)
            Text("Break it down!")
        }

として実行したのを長押ししてみると有効化したものについては"copy"、"share"が出てきます。

List(0..<100) { index in
    Text("Row \(index)")
}
.textSelection(.enabled)

Listに関しても同じように有効にすることができます。

bordered buttons

ボタンのカスタマイズを簡単にすることができるようになりました。

Button("New action") {}
    .buttonStyle(.bordered)

モディファイアをつけることによってボタンのバックグラウンドなどの状況を変えることができます。

VStack{
            Button("new Button") {
                print("action")
            }
            .buttonStyle(.bordered)
            Button("new Button") {
                print("action")
            }
            .buttonStyle(.borderedProminent)
            Button("new Button") {
                print("action")
            }
                .tint(.green)
                .buttonStyle(.bordered)
                .controlSize(.large)
        }

こんな感じになります。


この記事が気に入ったらサポートをしてみませんか?