Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to setup a newly create frameLayout? #5

Open
Gargo opened this issue Nov 13, 2023 · 3 comments
Open

How to setup a newly create frameLayout? #5

Gargo opened this issue Nov 13, 2023 · 3 comments

Comments

@Gargo
Copy link

Gargo commented Nov 13, 2023

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?

@kennic
Copy link
Owner

kennic commented Nov 14, 2023

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
override open func layoutSubviews() {
    super.layoutSubviews()
    frameLayout.frame = bounds
}

// or if frameLayout was placed inside an UIViewController
override func viewDidLayoutSubviews() {
    super.viewDidLayoutSubviews()
    frameLayout.frame = view.bounds
}

@Gargo
Copy link
Author

Gargo commented Nov 20, 2023

@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

@kennic
Copy link
Owner

kennic commented Nov 20, 2023

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().

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants