         }
     }
     
-    func positionLabelInCenterOfView(_ view: UIView) {
-        label.frame = view.frame
-    }
-
-    
     func positionLabelAboveView(_ view: UIView) {
-    
+        
         let viewTop = view.frame.origin.y
-        label.frame = CGRect(x: 0,
-                             y: 0,
-                             width: contentView.bounds.size.width,
-                             height: viewTop)
+        let frame = CGRect(x: 0,
+                           y: 0,
+                           width: contentView.bounds.size.width,
+                           height: viewTop)
+        positionLabelWithinFrame(frame: frame)
     }
     
     func positionLabelBelowView(_ view: UIView) {
         
         let viewBottom = view.frame.origin.y + view.frame.size.height
-        label.frame = CGRect(x: 0,
-                             y: viewBottom,
-                             width: contentView.bounds.size.width,
-                             height: contentView.bounds.size.height - viewBottom)
+        let frame = CGRect(x: 0,
+                           y: viewBottom,
+                           width: contentView.bounds.size.width,
+                           height: contentView.bounds.size.height - viewBottom)
+        positionLabelWithinFrame(frame: frame)
+        
     }
     
     func positionLabelToLeftOfView(_ view: UIView) {
         
         let viewStartX = view.frame.origin.x
-        label.frame = CGRect(x: 0,
-                             y: 0,
-                             width: viewStartX,
-                             height: contentView.bounds.size.height)
+        let frame = CGRect(x: 0,
+                           y: 0,
+                           width: viewStartX,
+                           height: contentView.bounds.size.height)
+        positionLabelWithinFrame(frame: frame)
+        
     }
     
     func positionLabelToRightOfView(_ view: UIView) {
         
         let viewEndX = view.frame.origin.x + view.frame.size.width
-        label.frame = CGRect(x: viewEndX,
-                             y: 0,
-                             width: contentView.bounds.size.width - viewEndX,
-                             height: contentView.bounds.size.height)
+        let frame = CGRect(x: viewEndX,
+                           y: 0,
+                           width: contentView.bounds.size.width - viewEndX,
+                           height: contentView.bounds.size.height)
+        positionLabelWithinFrame(frame: frame)
+        
+    }
+    
+    func positionLabelWithinFrame(frame: CGRect) {
+        
+        label.transform = CGAffineTransform.identity
+        
+        var frame = frame
+        let margin = CGFloat(8)
+        
+        frame = CGRect(x: frame.origin.x + margin,
+                       y: frame.origin.y + margin,
+                       width: frame.size.width - margin*2,
+                       height: frame.size.height - margin*2)
+        
+        
+        let labelSize = label.sizeThatFits(CGSize(width: CGFloat.greatestFiniteMagnitude,
+                                                  height: frame.size.height))
+        
+        let newFrame = CGRect(x: frame.origin.x + (frame.size.width - labelSize.width)/2,
+                              y: frame.origin.y + (frame.size.height - labelSize.height)/2,
+                              width: labelSize.width,
+                              height: labelSize.height)
+        
+        label.frame = newFrame
+    
+        if labelSize.width > frame.size.width {
+            let scale = frame.size.width / labelSize.width
+            label.transform = CGAffineTransform(scaleX: scale, y: scale)
+        }
     }
     
     func configureWithItem(item: ExampleItem) {

        textPosition = item.textPosition
        label.text = item.text
        label.superview?.bringSubview(toFront: label)
        setNeedsLayout()
        layoutIfNeeded()
    }

        
        switch textPosition {
        case .center:
            positionLabelWithinFrame(frame: contentView.bounds)
        case .centerInView(let viewNumber):
            if let view = views[viewNumber] {
                positionLabelWithinFrame(frame: view.frame)
            }
        case .aboveView(let viewNumber):
            if let view = views[viewNumber] {
