1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

[SwiftUI]IgnoreSafeAreaとScaleToFillを使用すると、画像が右にズレる問題

Last updated at Posted at 2024-12-27

はじめに

以下のようなコードを書くと、画像が右にズレる現象が起きたので、その解決策を調べます。

content
    .background(
        image
            .resizable()
            .scaledToFill()
            .ignoresSafeArea(.container, edges: [.top])
    )

実装

content
    .background(
        image
            .resizable()
            .scaledToFill()
+            .frame(minWidth: 0, maxWidth: .infinity)
            .ignoresSafeArea(.container, edges: [.top])
    )

おわりに

frameを明示的に指定してあげることで、中心点がずれないようになりました。

参考

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?