Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //
- // ScrollableCaptionLayout.swift
- // curate-admin
- //
- // Created by Steve Cox on 1/20/17.
- // Copyright © 2017 Steve Cox. All rights reserved.
- //
- import UIKit
- import LayoutKit
- class ScrollableCaptionLayout: SizeLayout<UIScrollView> {
- init(text: String, font: UIFont = defaultFont, contentWidth: CGFloat, scrollViewSize: CGSize) {
- let caption = LabelLayout(
- text: text,
- font: font,
- config: { label in
- label.textColor = UIColor(red: 49.0/255.0, green: 61.0/255.0, blue: 82.0/255.0, alpha: 1.0)
- }
- )
- let captionViewHeight = caption.arrangement(width: contentWidth).frame.height
- let captionContentLayout = SizeLayout<View>(
- width: contentWidth,
- height: captionViewHeight,
- alignment: .topLeading,
- flexibility: Flexibility.inflexible,
- sublayout: caption,
- config: { (view: View) in
- view.backgroundColor = UIColor.white
- }
- )
- super.init(
- minWidth: scrollViewSize.width,
- maxWidth: scrollViewSize.width,
- minHeight: scrollViewSize.height,
- maxHeight: scrollViewSize.height,
- alignment: Alignment.topLeading,
- flexibility: Flexibility.flexible,
- viewReuseId: nil,
- sublayout: nil,
- config: { view in
- let captionContentLayoutView = captionContentLayout.arrangement().makeViews()
- view.addSubview(captionContentLayoutView)
- view.contentSize = captionContentLayoutView.bounds.size
- }
- )
- }
- }
- private let defaultFont = UILabel().font ?? UIFont.systemFont(ofSize: 17)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement