7
4

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

[SwiftUI]UIHostingControllerの最小サイズを取得する

Posted at

SwiftUIをUIKitの世界に連れてくるにはUIHostingControllerを利用し、UIKitのコンポーネントとしてコンテナ化します。
モーダルなどとして利用する場合は、UIHostingControllerをそのまま使えば良いですがコンテナビューとして使いたい時は最小サイズが知りたくなります。
sizeThatFitsのメソッドが生えているので、そこに対してInt.maxのサイズを渡してあげれば最小をとることができます。

let hostingController = UIHostingController(rootView: content())
let size = hostingController.sizeThatFits(in: CGSize(width: Int.max, height: Int.max))
7
4
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
7
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?