Skip to content

Instantly share code, notes, and snippets.

@novinfard
Created October 9, 2018 11:06
Show Gist options
  • Select an option

  • Save novinfard/5f38ffd566ffd579c59da1b80bb716df to your computer and use it in GitHub Desktop.

Select an option

Save novinfard/5f38ffd566ffd579c59da1b80bb716df to your computer and use it in GitHub Desktop.
[Padded Label]
import UIKit
class UIPaddedLabel: UILabel {
var padding = UIEdgeInsets(top: 0, left: 0, bottom: 0, right: 0)
public override func drawText(in rect: CGRect) {
super.drawText(in: UIEdgeInsetsInsetRect(rect, padding))
}
public override var intrinsicContentSize: CGSize {
let size = super.intrinsicContentSize
return CGSize(width: size.width + padding.left + padding.right,
height: size.height + padding.top + padding.bottom)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment