【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)
    )

coiai.netでは案件受付中です。
Vtuber、建築モデリング、EC構築、ネイティブアプリ制作、制服の制作(実は縫製業もメイン)、Vision Pro向けアプリ etc…
様々な制作開発を行っています。

ご気軽にご相談ください!

コイアイちゃん Avatar

この記事を書いたのは


Comments

Leave a Reply

Your email address will not be published. Required fields are marked *

CAPTCHA


Top
About
Blog
contact