Advertisement
Guest User

Untitled

a guest
Jan 20th, 2017
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.74 KB | None | 0 0
  1. //
  2. // ScrollableCaptionLayout.swift
  3. // curate-admin
  4. //
  5. // Created by Steve Cox on 1/20/17.
  6. // Copyright © 2017 Steve Cox. All rights reserved.
  7. //
  8.  
  9. import UIKit
  10. import LayoutKit
  11.  
  12. class ScrollableCaptionLayout: SizeLayout<UIScrollView> {
  13.  
  14. init(text: String, font: UIFont = defaultFont, contentWidth: CGFloat, scrollViewSize: CGSize) {
  15.  
  16. let caption = LabelLayout(
  17. text: text,
  18. font: font,
  19. config: { label in
  20. label.textColor = UIColor(red: 49.0/255.0, green: 61.0/255.0, blue: 82.0/255.0, alpha: 1.0)
  21. }
  22. )
  23.  
  24. let captionViewHeight = caption.arrangement(width: contentWidth).frame.height
  25. let captionContentLayout = SizeLayout<View>(
  26. width: contentWidth,
  27. height: captionViewHeight,
  28. alignment: .topLeading,
  29. flexibility: Flexibility.inflexible,
  30. sublayout: caption,
  31. config: { (view: View) in
  32. view.backgroundColor = UIColor.white
  33. }
  34. )
  35.  
  36. super.init(
  37. minWidth: scrollViewSize.width,
  38. maxWidth: scrollViewSize.width,
  39. minHeight: scrollViewSize.height,
  40. maxHeight: scrollViewSize.height,
  41. alignment: Alignment.topLeading,
  42. flexibility: Flexibility.flexible,
  43. viewReuseId: nil,
  44. sublayout: nil,
  45. config: { view in
  46. let captionContentLayoutView = captionContentLayout.arrangement().makeViews()
  47. view.addSubview(captionContentLayoutView)
  48. view.contentSize = captionContentLayoutView.bounds.size
  49. }
  50. )
  51. }
  52.  
  53. }
  54.  
  55. private let defaultFont = UILabel().font ?? UIFont.systemFont(ofSize: 17)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement