Skip to content

How to setup a newly create frameLayout? #5

Open

Description

@Gargo

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?

Activity

  1. kennic commented on Nov 14, 2023

    @kennic
    Owner

    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
    }
  2. Gargo commented on Nov 20, 2023

    @Gargo
    Author

    @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

  3. kennic commented on Nov 20, 2023

    @kennic
    Owner

    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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions