You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

30 lines
985 B

6 years ago
  1. //
  2. // LabelExtension.swift
  3. // GMERemittance
  4. //
  5. // Created by Sujal on 3/2/18.
  6. // Copyright © 2018 Gobal Money Express Co. Ltd. All rights reserved.
  7. // Creates a padding to the left and right of the label with a value of 5
  8. //
  9. import UIKit
  10. class PaddedLabel : UILabel
  11. {
  12. var edgeInsets:UIEdgeInsets = UIEdgeInsets(top: 0, left: 5, bottom: 0, right: 5)
  13. override func textRect(forBounds bounds: CGRect, limitedToNumberOfLines numberOfLines: Int) -> CGRect {
  14. var rect = super.textRect(forBounds: UIEdgeInsetsInsetRect(bounds, edgeInsets), limitedToNumberOfLines: numberOfLines)
  15. rect.origin.x -= edgeInsets.left
  16. rect.origin.y -= edgeInsets.top
  17. rect.size.width += (edgeInsets.left + edgeInsets.right);
  18. rect.size.height += (edgeInsets.top + edgeInsets.bottom);
  19. return rect
  20. }
  21. override func drawText(in rect: CGRect) {
  22. super.drawText(in: UIEdgeInsetsInsetRect(rect, edgeInsets))
  23. }
  24. }