Latest 2.1.0
License MIT
Platforms ios 9.0
Frameworks UIKit

CI Status
Readme Score

This MMSLayeredView class provides the features for layering UIViews on a background view and saving the composite image to a png file. The layered views can be moved, resized, and scaled within the confines of the view’s frame.


Basic Usage

To run the example project, clone the repo, and run pod install from the Example directory first.

Create a MMSLayeredView object. Add it to a subview of one of the application’s UIViewController subclasses. Or in Interface Builder add a UIView to a subview of one of the UIViewControllers. In the Identity Inspector, select the class MMSLayeredView. Size it as you see fit for your application’s needs.

Add a background view to the object. The background view can be a UIView or any subclass of UIView. Typically, you would add a UIImageView as the background view. Call the method addBackgroundView to set the background view.

override func viewDidLoad() {

    let exampleLayeredView = MMSLayeredView.init(frame: CGRectMake(20.0, 20.0, 100.0, 100.0))


    let backgroundImage = UIImage.init(named: "example.jpg")

    let backgroundView = UIImageView(image: backgroundImage)

    backgroundView.contentMode = .ScaleToFill



addBackgroundImage adds the view to the subview, resizes the height and width to match the dimensions of exampleLayeredView and sets the frame’s origin to (0,0).

Once the background view is set, all subviews added will display above the background view in the z-order. The background view can be set in a sequence with respect to adding subviews; it will always display behind all the subviews in the z-order.

Set a unique tag for the view to access any one of the subviews with the method:


Add, remove, and reorder subviews to the layered view with UIView view hiearchy methods:



    insertSubview(view:UIView, atIndex: Int)

    insertSubview(view: UIView, aboveSubview: UIView)

    insertSubview(view: UIView, belowSubview: UIView)

    exchangeSubviewAtIndex(index1: Int, withSubviewAtIndex: Int)

    sendSubviewToBack(view: UIView)

    bringSubviewToFront(view: UIView)

The user selects one of the subviews for the focus of application operations by tapping the view. When tapped the view shows it has focus by filling the area outside it’s perimeter with a translucent black. To get the UIView with focus access the property:

public var viewWithFocus: UIView?

Finally, this class supports the capability for merging the background view and subviews into image. With this feature, you can use the class to build applications providing the feature to layer text over images, decorate images with stickers, or both. This is the public method supporting export to image:

public func mergeTextAndImage() -> UIImage?

User Interaction

This class gives the application user the following operations:

  • Scale Subview: Pinch gesture.
  • Move Subview: Double tap to give move focus to the view then drag it.
  • Size Subview: One finger drag gesture to size dimensions independently.
  • Give Subview Focus: One finger tap gesture gives focus to a subview and removes it when it already has focus. Tap the background view to give it focus.


  • MMSLayeredView requires iOS 8.3 or later.
  • Swift 3.0


MMSLayeredView is available through CocoaPods. To install
it, simply add the following line to your Podfile:

pod "MMSLayeredView"


William Miller, [email protected]


This project is is available under the MIT license. See the LICENSE file for more info. Add attibution by linking to the project page is appreciated.

Latest podspec

    "name": "MMSLayeredView",
    "version": "2.1.0",
    "summary": "Provides the features to layer views on top of a background view with gestures to move, scale, resize, and give them focus.",
    "description": "This class supports layering 1 or more views upon a background view. The user can resize, scale, and move each subview. They can select one of them for focus of operations and set a background view.  The class supports a method to merge the background and subviews into an image.  Use the pinch gesture to scale a subview; two finger drag gesture to move a subview; one finger drag gesture to size each dimension independently; and the tap gesture to change or remove focus.  One application of this class would be to layer text over a photo and export the merged image to a file for submitting to your text messages or social networks.  Another application would be for an application to add decorations to an image.",
    "homepage": "",
    "screenshots": "",
    "license": {
        "type": "MIT",
        "file": "LICENSE"
    "authors": {
        "William Miller": "[email protected]"
    "source": {
        "git": "",
        "tag": "2.1.0"
    "platforms": {
        "ios": "9.0"
    "source_files": "MMSLayeredView/Classes/**/*",
    "frameworks": "UIKit",
    "pushed_with_swift_version": "4.0"

Pin It on Pinterest

Share This