Created
September 13, 2014 23:39
-
-
Save karloscarweber/004685c33b7a1398518a to your computer and use it in GitHub Desktop.
UILabel subclass that makes setting padding really easy.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// 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)) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
How do you use this???