Questions tagged [uihostingcontroller]

78 questions
36
votes
6 answers

UIHostingController should expand to fit contents

I have a custom UIViewControllerRepresentable (layout-related code shown below). This tries to replicate the native SwiftUI ScrollView, except it scrolls from the bottom except the top. View hierarchy view: UIView | \- scrollView: UIScrollView | …
Potassium Ion
  • 2,075
  • 1
  • 22
  • 39
18
votes
7 answers

Why does SwiftUI UIHostingController have extra spacing?

I'm trying to add a SwiftUI view to UIKit view using UIHostingController and it shows extra spacing(This sample is made to simulate an issue on a production app). Here is the screenshot. Layout overview: View UIStackView UIImageView …
Daniel
  • 507
  • 6
  • 22
18
votes
2 answers

On iOS 15, the UIHostingController is adding some weird extra padding to its hosting SwiftUI view (_UIHostingView)

UPDATE: 2022-09-26 This issue has been fixed on iOS 16. Although the issue is still present on iOS 15 even when the project is compiled with the iOS 16 SDK. Original question: On iOS 15, the UIHostingController is adding some weird extra padding to…
Luis Ascorbe
  • 1,985
  • 1
  • 22
  • 36
14
votes
1 answer

How to set UIHostingController's background color to clear?

I need to be able to see through my SwiftUI Views as well as the UIHosting Controller presenting them in order to see a background image underneath them. The code below still shows a white rectangle under my SwiftUI View. Paul Hudson says to use…
GarySabo
  • 5,806
  • 5
  • 49
  • 124
12
votes
7 answers

Cannot place SwiftUI view outside the SafeArea when embedded in UIHostingController

I have a simple SwiftUI view that contains 3 text elements: struct ImageDescriptionView: View { var title: String? var imageDescription: String? var copyright: String? var body: some View { VStack(alignment: .leading) { …
WalterBeiter
  • 2,021
  • 3
  • 23
  • 48
12
votes
3 answers

Add SwiftUI View to an UITableViewCell contentView

I'm currently trying, to implement a UITableViewController in a UIViewControllerRepresentable, where the contents of the cells are SwiftUI Views again. I cannot use a SwiftUI List, because I want to add an UISearchController later on. Because I want…
Josef Zoller
  • 921
  • 2
  • 8
  • 24
10
votes
3 answers

SwiftUI - How to access UIHostingController from SwiftUI

I have SwiftUI page, it's being navigated from UIKit view. I want to set a title to this page, what I'm doing is // code of UIKit view let controller = UIHostingController(rootView: SwiftUIView()) controller.title =…
Leo Yang
  • 113
  • 1
  • 5
9
votes
2 answers

How to check if a view controller is of type UIHostingController

i have a UIHostingController that is hosting a SwiftUI view called CatalogView. when showing it, an environment object is attached, so basically from UIKit it is shown like this: let rootCatalogView = CatalogView() let appState = AppState.get() let…
memical
  • 2,353
  • 1
  • 24
  • 36
7
votes
2 answers

Hide UINavigationController's navigationBar when the root controller is a UIHostingController

I am struggling to hide the navigationBar, which would properly be hidden if the root controller wasn't a SwiftUI UIHostingController. I tried the following: Setting navigationController.isNavigationBarHidden = true after creating it, at…
6
votes
2 answers

SwiftUI UIHostingController navigation title animation broken

When I use a UIHostingController to push a new SwiftUI.View to the navigation stack of an existing UIKit UIViewController the animation of the title in the navigation bar is broken. I tested in Xcode 12.0 on a pure new project. Watch carefully the…
Darko
  • 9,655
  • 9
  • 36
  • 48
6
votes
0 answers

SwiftUI from UIHostingController: showing ActionSheet gives warning about detached view controller

I have created a SwiftUI view which I show in a MKMapView's annotation callout. I use UIHostingController to wrap the SwiftUI view, and use annotationView's detailCalloutAccessoryView property to set the view and display it. This works fine for the…
Z S
  • 7,039
  • 12
  • 53
  • 105
6
votes
2 answers

Swift UI: UIHostingController.view is not fit to content view size at iOS 13

I want to update Swift UI View according to the communication result. But UIHostingController.view is not fit rootView size at iOS 13. The same thing happens when I try with the sample code below. I want to add self-sizing SwiftUI View to…
5
votes
1 answer

iOS 16 NavigationBar sets large title and hides inline title

When checking our app for bugs on iOS 16 we have realized that behavior on the NavigationBar changes, even on non 14 Pro models. There are multiple issues and we are wondering how to fix them. All issues came with no change in code. Just running the…
JanMensch
  • 1,720
  • 1
  • 18
  • 27
5
votes
0 answers

Forwarding touches from SwiftUI View with transparent background to UIKit view

I have a large SwiftUI view that contains a bottom menu and some small UI components above it. I want to overlay this view on top of an existing UIViewController instance and therefore using a UIHostingController. The problem I'm having is that, the…
Cihan Tek
  • 5,349
  • 3
  • 22
  • 29
5
votes
1 answer

UIHostingController view's transform gets out of sync when superview is translated before viewDidAppear

Given: UIHostingController hosted inside UIKit superview. When: Superview transform modified before viewDidAppear. In this example moved 200pts down. Then: Subsequent changes to superview transform will be out of sync. In this example I moved it…
1
2 3 4 5 6