axxe16
9/13/2014 - 11:39 PM

UILabel subclass that makes setting padding really easy.

UILabel subclass that makes setting padding really easy.

//
//  UIBorderedLabel.swift
//  standToMake
//
//  Created by Karl Oscar Weber on 9/13/14.
//  Copyright (c) 2014 Karl Oscar Weber. All rights reserved.
//
//  Thanks to: http://userflex.wordpress.com/2012/04/05/uilabel-custom-insets/

import UIKit

class UIBorderedLabel: UILabel {

    var topInset:       CGFloat = 0
    var rightInset:     CGFloat = 0
    var bottomInset:    CGFloat = 0
    var leftInset:      CGFloat = 0
    
    override func drawTextInRect(rect: CGRect) {
        var insets: UIEdgeInsets = UIEdgeInsets(top: self.topInset, left: self.leftInset, bottom: self.bottomInset, right: self.rightInset)
        self.setNeedsLayout()
        return super.drawTextInRect(UIEdgeInsetsInsetRect(rect, insets))
    }

}