5
3

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 1 year has passed since last update.

【SwiftUI】角丸のImageに枠線をつける

Posted at

角丸じゃない写真の場合

これは簡単にできる。

struct BorderImage: View {
    var body: some View {
        Image("monkey")
            .resizable()
            .aspectRatio(contentMode: .fit)
            .frame(width: 350)
            .border(.red, width: 10)
    }
}

角丸の写真の場合

角丸部分のborderが消えてしまう。

struct BorderImage: View {
    var body: some View {
        Image("monkey")
            .resizable()
            .aspectRatio(contentMode: .fit)
            .frame(width: 350)
            .border(.red, width: 2)
            .cornerRadius(50)
    }
}

overlayを使って実現する

struct BorderImage: View {
    var body: some View {
        Image("monkey")
            .resizable()
            .aspectRatio(contentMode: .fit)
            .frame(width: 350)
            .cornerRadius(50)
            .overlay(
                RoundedRectangle(cornerRadius: 50)
                    .stroke(.red, lineWidth: 2)
            )
    }
}

おわりに

写真は何の関係もないです。

5
3
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
5
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?