Make subview fit to parent view frame?
Having trouble finding any topics on here which address this: I have a parent View which I present as a sheet, and I programmatically add a subview to it, but I want that subview to be constrained to the size of its parent view.
I thought that setting the subview flex to 'WH' might do it, or setting the parent view's content_mode to ui.CONTENT_SCALE_TO_FILL might do it. But the subview always sets its size to whatever its frame is set to, and doesn't fill or shrink to the parent view.
Here's ultra-simplistic code:
v = ui.load_view("base_view.pyui") sub = ui.Button() sub.frame(0,0,100,30) sub.title = "Button" sub.flex = "WH" sub.border_width = 1 v.add_subview(sub) v.present("sheet")
base_view.pyui is just a View with a size, no content, no custom View class.
This loads and presents fine, the button is visible at the assigned size and position...but I want a way to make sure it sizes itself to the parent view automatically (not by directly setting its frame to that of its parent). Is this doable?
@shinyformica, if I understand your requirement right, it is as simple as:
button.frame = v.bounds button.flex = 'WH'