iosswiftuicontainerviewcontainer-view

Swift Change UIContainerView height and width


I have two ContainerView which are placed above each other,for example ContainerA is front of ContainerB.

When a Button tapped ContainerA width and height should change to a smaller size, then ContainerB will be shown.

How can I change height and width of a container view using swift instead of story board? does it have something like transform?


Solution

  • change its frame:

    let currentContainerViewFrame = containerView?.frame
    currentContainerViewFrame?.width -= 200
    currentContainerViewFrame?.height -= 200
    containerView?.frame = currentContainerViewFrame
    

    or work with its transform property:

    containerView?.transform = CGAffineTransformScale(CGAffineTransformIdentity, 0.7, 0.7)