Last active
April 18, 2020 21:38
-
-
Save siempay/49530abc6593552041752d0a3df36cfc to your computer and use it in GitHub Desktop.
UILabel subclass that makes setting padding really easy for Swift 5 users
This file contains hidden or 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 | |
// 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)) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Please update for Swift 4