LoginSignup
1
1

More than 1 year has passed since last update.

【SwiftUI】Viewの境界線を描くには

Last updated at Posted at 2021-12-07

[Q] SwiftUIでViewの境界線を描くには?

[A] border を使います

  Text(Hello, world!)
    .border(Color.gray, width: 2)

以下は SwiftPlayground で実行できる簡単なサンプルです。

import SwiftUI
import PlaygroundSupport

struct Preview: View {
  var body: some View {
    Text(Hello, world!)
      .border(Color.gray, width: 2) // この行がポイント
  }
}

PlaygroundPage.current.setLiveView(Preview())

動作確認環境

2021/12/07 に確認しました。

  • iPad Pro
  • iPad OS 15.1
  • Playgrounds 3.4.1(1302.34)

参考

  • Apple Developer Documentation
1
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
1
1