Skip to content

Instantly share code, notes, and snippets.

@karloscarweber
Created September 13, 2014 23:39
Show Gist options
  • Star 7 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save karloscarweber/004685c33b7a1398518a to your computer and use it in GitHub Desktop.
Save karloscarweber/004685c33b7a1398518a 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))
}
}
@lenichols
Copy link

How do you use this???

@siempay
Copy link

siempay commented Jul 11, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment