2
2

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 3 years have passed since last update.

SwiftUIで点線を引く方法

Posted at

#1.区切り線を引く
◯区切るために線を引くとき

Divider()を使う

1.縦で区切る

HStack {
    Text("左左左左左")
    Divider()
    Text("右右右右右")
}

image.png

2.横で区切る
今度は、HStackのところをVStackに("H"orizon から "V"erticalに)

#2.点線の場合
◯線のスタイルはStrokeStyle構造体で定義される
例えば点線のボタンを作るなら、

Button(action: {
    print("Hello button tapped!")
}) {
    Text("Hello World")
        .fontWeight(.bold)
        .font(.title)
        .foregroundColor(.purple)
        .padding()
        .overlay(
            Capsule(style: .continuous)
                .stroke(Color.purple, style: StrokeStyle(lineWidth: 5, dash: [10]))
        )
}

のようになる。

最後の.strokeのStrokeStyleに注目すると、StrokeStyle(lineWidth: 5, dash: [10]))
となっている。

つまり、これは線の太さが5、長さが10の点線が出来上がることを意味する

点線(破線)はdash[線の長さ, 空白の長さ]で指定する

2
2
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
2
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?