【SwiftUI】Link
今回は、iOS14で追加になったLink表示についてです。
試した画面表示とコードを掲載します。テキストリンクと画像アイコンの2パターンで表示してます。どちらのタップすると
Appleのサイトに遷移するようになっております。
試した画面表示とコードを掲載します。テキストリンクと画像アイコンの2パターンで表示してます。どちらのタップすると
Appleのサイトに遷移するようになっております。
・画面表示
遷移前と遷移後の画面を掲載します。
・遷移前画面
・遷移後画面
・コード
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import SwiftUI | |
struct ContentView: View { | |
var body: some View { | |
VStack { | |
Text("・表示例:テキストリンク") | |
Link("Appleサイト", destination: URL(string: "https://www.apple.com/jp/?afid=p238%7Cs5w8NM0Tc-dc_mtid_18707vxu38484_pcrid_516140409017_pgrid_13140806901_&cid=aos-jp-kwgo-brand--slid---product--")!) | |
Spacer().frame(height: 50.0) | |
Text("・表示例:画像リンク") | |
Link(destination: URL(string: "https://www.apple.com/jp/?afid=p238%7Cs5w8NM0Tc-dc_mtid_18707vxu38484_pcrid_516140409017_pgrid_13140806901_&cid=aos-jp-kwgo-brand--slid---product--")!) { | |
Image(systemName: "link.circle.fill") | |
.font(.largeTitle).accentColor(Color.orange) | |
} | |
} | |
} | |
} |