Advertisement
Guest User

Untitled

a guest
Oct 21st, 2016
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.10 KB | None | 0 0
  1. //
  2. // RoundedLabel.swift
  3. //
  4. // Created by Vasily Ulianov on 20.10.16.
  5. //
  6.  
  7. import UIKit
  8.  
  9. @IBDesignable
  10. class RoundedLabel: UILabel {
  11.  
  12. var edgeInsets: UIEdgeInsets {
  13. if autoPadding {
  14. if cornerRadius == 0 {
  15. return UIEdgeInsetsZero
  16. } else {
  17. return UIEdgeInsets(top: 1, left: 3, bottom: 1, right: 3)
  18. }
  19. } else {
  20. return UIEdgeInsets(top: verticalPadding, left: horizontalPadding, bottom: verticalPadding, right: horizontalPadding)
  21. }
  22. }
  23.  
  24. @IBInspectable var horizontalPadding: CGFloat = 0
  25. @IBInspectable var verticalPadding: CGFloat = 0
  26. @IBInspectable var autoPadding: Bool = true
  27.  
  28. @IBInspectable var cornerRadius: CGFloat = 0 {
  29. didSet {
  30. layer.cornerRadius = cornerRadius
  31. layer.masksToBounds = cornerRadius > 0
  32. }
  33. }
  34.  
  35. override func drawTextInRect(rect: CGRect) {
  36. super.drawTextInRect(UIEdgeInsetsInsetRect(rect, edgeInsets))
  37. }
  38.  
  39. override func intrinsicContentSize() -> CGSize {
  40. var size = super.intrinsicContentSize()
  41.  
  42. let edgeInsets = self.edgeInsets
  43. size.width += edgeInsets.left + edgeInsets.right
  44. size.height += edgeInsets.top + edgeInsets.bottom
  45.  
  46. return size
  47. }
  48.  
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement