Drawing a Component insiede a UIView


#1

Hi everybody!
I’m trying to draw a component inside a UIView, but I can’t find the right method!

Can someone please help me :slight_smile:


#2

now I’m using Component->getWindowHandle() to get the pointer to the UIView of the Component, but if I try to set the viewController’ view anything happens.
My code now is something like this

UIView* myView = (UIView*)myComponent->getWindowHandle();
[self setView:myView];


#3

I think you need to look at the UIViewComponent class!


#4

…oh no, sorry, just re-read your post, and that’s the opposite of what you want.

In fact, you’d want to pass the parent’s UIView* as the handle to the Component::addToDesktop method.


#5

Exactly, I can get the parent *UIView, but I cannot assign it to the ios ViewController of XIb


#6

I think as Jules said you need to use the addToDesktop method to make the component actually draw into the UIView. You might also need to call setVisible and make sure it has a size. I use a function which looks like this to do exactly what you’re asking:

static void addComponentToUIView (Component& comp, UIView* uiView) { comp.addToDesktop (0, (void*) uiView); comp.setVisible (true); comp.setBounds (uiView.bounds.origin.x, uiView.bounds.origin.y, uiView.bounds.size.width, uiView.bounds.size.height); }


#7

Thanks guys!
I’ve just seen this other post
https://www.rawmaterialsoftware.com/viewtopic.php?f=4&t=7955

it works perfectly! :slight_smile: