![見出し画像](https://assets.st-note.com/production/uploads/images/69662966/rectangle_large_type_2_a49293846e2b1dc25965494b16cc02fb.png?width=800)
SwiftUIでいこう! -その他いろいろ(new!)-3
SF Symbols
SF Symbolsを使った画像の表示の方法を簡単にカスタマイズできるようになりました。
hierarchical ・・・ multiple layers
monochrome ・・・single layer filled with the foreground style
multicolor ・・・・multiple layers with their inherit styles
palette ・・・multiple layers, with different styles applied to the layers
4種類が用意されています。
Image(systemName: "exclamationmark.triangle.fill")
.symbolRenderingMode(.hierarchical)
.font(.system(size: 100))
Image(systemName: "exclamationmark.triangle.fill")
.symbolRenderingMode(.monochrome)
.font(.system(size: 100))
Image(systemName: "exclamationmark.triangle.fill")
.symbolRenderingMode(.multicolor)
.font(.system(size: 100))
Image(systemName: "exclamationmark.triangle.fill")
.symbolRenderingMode(.palette)
.font(.system(size: 100))
で並べてみると
![](https://assets.st-note.com/img/1642382597155-DZuegQKR1t.png?width=800)
dismissed with a swipe
必ずボタンで閉じる。スワイプで勝手に閉じるのを防ぐ。
show an alert
今までのものは使えないようになり新しく変更されています。
struct ContentView: View {
@State private var showingAlert = false
var body: some View {
Button("Show Alert") {
showingAlert = true
}
.alert("Important message", isPresented: $showingAlert) {
Button("OK", role: .cancel) { }
}
}
}
今まではAlert()使っていたがモディファイアで実装することになった。iOS14以前に対応する場合は"Alert()"を使う。
confirmationDialog()
ActionSheetは非推奨(Deprecated)となりconfirmationDialog()を使うようになった。
alertとの違いは
複数の選択肢を指定
することができます。
VStack {
Text(selection)
Button("Confirm paint color") {
showingOptions = true
}
.confirmationDialog("Select a color", isPresented: $showingOptions, titleVisibility: .visible) {
Button("Red") {
selection = "Red"
}
Button("Green") {
selection = "Green"
}
Button("Blue") {
selection = "Blue"
}
}
}
iOS14以前はActionSheetを使って実装する必要がある。
foreground styles
HStack {
Image(systemName: "clock.fill")
Text("Dreams")
}
.font(.system(size: 100))
.foregroundStyle(
.linearGradient(
colors: [.red, .black],
startPoint: .top,
endPoint: .bottom
)
)
実行すると
![](https://assets.st-note.com/img/1642405959089-WxtiIZvqSY.png?width=800)
この記事が気に入ったらサポートをしてみませんか?