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.

41 lines
1.1 KiB

5 years ago
  1. //
  2. // UIButton_Ext.swift
  3. // GME Remit
  4. //
  5. // Created by InKwon James Kim on 2019/11/28.
  6. // Copyright © 2019 Gobal Money Express Co. Ltd. All rights reserved.
  7. //
  8. import UIKit
  9. extension UILabel {
  10. func adjustsFontSizeToFitWidth(_ boolean: Bool, scale: CGFloat) {
  11. minimumScaleFactor = scale
  12. adjustsFontSizeToFitWidth = boolean
  13. }
  14. func setLineSpacing(lineSpacing: CGFloat = 0.0, lineHeightMultiple: CGFloat = 0.0) {
  15. guard let labelText = self.text else { return }
  16. let paragraphStyle = NSMutableParagraphStyle()
  17. paragraphStyle.lineSpacing = lineSpacing
  18. paragraphStyle.lineHeightMultiple = lineHeightMultiple
  19. let attributedString:NSMutableAttributedString
  20. if let labelattributedText = self.attributedText {
  21. attributedString = NSMutableAttributedString(attributedString: labelattributedText)
  22. } else {
  23. attributedString = NSMutableAttributedString(string: labelText)
  24. }
  25. attributedString.addAttribute(
  26. NSAttributedString.Key.paragraphStyle,
  27. value:paragraphStyle,
  28. range: NSMakeRange(0, attributedString.length)
  29. )
  30. self.attributedText = attributedString
  31. }
  32. }