Skip to content

Instantly share code, notes, and snippets.

@karltaylor
Forked from karloscarweber/UIBorderedLabel.swift
Created December 1, 2016 14:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save karltaylor/ad0c84e922cab90a1ca5096ad25604ed to your computer and use it in GitHub Desktop.
Save karltaylor/ad0c84e922cab90a1ca5096ad25604ed to your computer and use it in GitHub Desktop.
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))
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment