Skip to content

Instantly share code, notes, and snippets.

@siempay
Last active April 18, 2020 21:38
Show Gist options
  • Save siempay/49530abc6593552041752d0a3df36cfc to your computer and use it in GitHub Desktop.
Save siempay/49530abc6593552041752d0a3df36cfc to your computer and use it in GitHub Desktop.
UILabel subclass that makes setting padding really easy for Swift 5 users
//
// UIBorderedLabel.swift
// app3
//
// Created by ELMSSILHA Brahim on 11/07/2017.
// Copyright © 2017 Brahim ELMSSILHA. All rights reserved.
//
import UIKit
class UIBorderedLabel: UILabel {
var topInset: CGFloat = 0
var rightInset: CGFloat = 0
var bottomInset: CGFloat = 0
var leftInset: CGFloat = 0
override func drawText(in rect: CGRect) {
let insets: UIEdgeInsets = UIEdgeInsets(
top: self.topInset,
left: self.leftInset,
bottom: self.bottomInset,
right: self.rightInset
)
self.setNeedsLayout()
return super.drawText(in: rect.inset(by: insets))
}
}
@danispringer
Copy link

Please update for Swift 4

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