Guest User

Untitled

a guest
Oct 19th, 2018
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.19 KB | None | 0 0
  1. //
  2. // LineSpacingLabel.swift
  3. // SimplePhotoMemo
  4. //
  5. // Created by osanai on 2018/10/09.
  6. // Copyright © 2018年 osanai. All rights reserved.
  7. //
  8.  
  9. // 行間をStoryboard上で調整する
  10.  
  11. import UIKit
  12.  
  13. class LineSpacingLabel: UILabel {
  14.  
  15. override func awakeFromNib() {
  16. super.awakeFromNib()
  17. setLineSpacingValue(value: self.lineSpace)
  18. }
  19.  
  20. @IBInspectable var lineSpace:CGFloat = 0 {
  21. didSet {
  22. self.setLineSpacingValue(value: lineSpace)
  23. }
  24. }
  25.  
  26. override var text:String? {
  27. didSet {
  28. self.setLineSpacingValue(value: self.lineSpace)
  29. }
  30. }
  31.  
  32. func set(text:String, lineSpace:CGFloat) {
  33. self.text = text
  34. setLineSpacingValue(value: lineSpace)
  35. }
  36.  
  37. func setLineSpacingValue(value:CGFloat) {
  38. let attrString = NSMutableAttributedString(string: self.text!)
  39. let style = NSMutableParagraphStyle()
  40. style.lineSpacing = value
  41. style.lineBreakMode = self.lineBreakMode
  42. attrString.addAttribute(.paragraphStyle,
  43. value: style,
  44. range: NSMakeRange(0, attrString.length))
  45. self.attributedText = attrString
  46. }
  47. }
Add Comment
Please, Sign In to add comment