You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Imagine the FrameLayout you just created as a picture frame containing various photos. If you move the picture frame or change its size, the photos inside will also move and their contents will adjust accordingly. Therefore, you just need to set the size of the picture frame to match the size you want to display.
In this case, just set like this:
// assume that frameLayout was placed inside another UIView
overrideopenfunc layoutSubviews(){
super.layoutSubviews()
frameLayout.frame = bounds
}
// or if frameLayout was placed inside an UIViewController
overridefunc viewDidLayoutSubviews(){
super.viewDidLayoutSubviews()
frameLayout.frame = view.bounds
}
@kennic what about to add functionality which allow to avoid that? I also know that sometimes layoutSubviews doesn't work properly and drawRect becomes the only way to get a valid frame
Actually, you can use an autoresizing mask for frameLayout to fit its frame to its superview. Please try that in your code. If it's not working, feel free to share your code here for further assistance.
Also, note that layoutSubviews will always be called after using setNeedsLayout().
When you create frameLayout its content is aligned. frameLayout is added to UIView like another common UIView.
But how to set frameLayout position and size in outer container? Should I use autolayout or autoresizing mask?
The text was updated successfully, but these errors were encountered: