【SwiftUI】動画を角丸にしたい

AvKitで読み込んだ動画にCornerRadiusをかけると、動画自体が飛び出してしまいます。下の感じ。

VideoPlayer(player: player)
    .aspectRatio(4 / 3, contentMode: .fit)
    .overlay(
        RoundedRectangle(cornerRadius: 20)
            .stroke(Color.purple, lineWidth: 2)
    )

これを直すには以下のように.clipShapeを追加すること。意外と簡単だったね。

VideoPlayer(player: player)
    .aspectRatio(4 / 3, contentMode: .fit)
    .clipShape(RoundedRectangle(cornerRadius: 20))
    .overlay(
        RoundedRectangle(cornerRadius: 20)
            .stroke(Color.purple, lineWidth: 2)
    )

Comments

コメントを残す

メールアドレスが公開されることはありません。 が付いている欄は必須項目です

CAPTCHA


Home
About
Blog
Works
Contact