//
//  PaddingLabel.swift
//  NaADae
//
//  Created by Lee on 2020/05/30.
//  Copyright © 2020 Kira. All rights reserved.
//

import UIKit

final class PaddingLabel: UILabel {
  let padding: UIEdgeInsets
  
  init(padding: UIEdgeInsets) {
    self.padding = padding
    super.init(frame: .zero)
  }
  
  required init?(coder: NSCoder) {
    fatalError("init(coder:) has not been implemented")
  }
  
  override func drawText(in rect: CGRect) {
    let paddingRect = rect.inset(by: padding)
    super.drawText(in: paddingRect)
  }
  
  override var intrinsicContentSize: CGSize {
    var contentSize = super.intrinsicContentSize
    contentSize.height += padding.top + padding.bottom
    contentSize.width += padding.left + padding.right
    return contentSize
  }
}

