Skip to content

Instantly share code, notes, and snippets.

@antonio081014
Created March 8, 2018 00:42
Show Gist options
  • Save antonio081014/774278d6ad56b9723ef5e3f77926049f to your computer and use it in GitHub Desktop.
Save antonio081014/774278d6ad56b9723ef5e3f77926049f to your computer and use it in GitHub Desktop.
//
// ScrollViewController.swift
//
// Created by Antonio081014 on 3/6/18.
// Copyright © 2018 sample.com. All rights reserved.
//
import UIKit
class ScrollViewController: UIViewController {
let text = """
Lorem ipsum dolor sit amet, in alia adhuc aperiri nam. Movet scripta tractatos cu eum, sale commodo meliore ea eam, per commodo atomorum ea. Unum graeci iriure nec an, ea sit habeo movet electram. Id eius assum persius pro, id cum falli accusam. Has eu fierent partiendo, doming expetenda interesset cu mel, tempor possit vocent in nam. Iusto tollit ad duo, est at vidit vivendo liberavisse, vide munere nonumy sed ex.
Quod possit expetendis id qui, consequat vituperata ad eam. Per cu elit latine vivendum. Ei sit nullam aliquam, an ferri epicuri quo. Ex vim tibique accumsan erroribus. In per libris verear adipiscing. Purto aliquid lobortis ea quo, ea utinam oportere qui.
"""
fileprivate let scrollView: UIScrollView = {
let scrollView = UIScrollView()
scrollView.translatesAutoresizingMaskIntoConstraints = false
scrollView.backgroundColor = .green
return scrollView
}()
fileprivate let contentView: UIView = {
let view = UIView()
view.translatesAutoresizingMaskIntoConstraints = false
view.backgroundColor = .purple
return view
}()
fileprivate let titleLabel: UILabel = {
let label = UILabel()
label.translatesAutoresizingMaskIntoConstraints = false
label.numberOfLines = 0
label.font = UIFont.preferredFont(forTextStyle: .headline)
label.textAlignment = .left
label.backgroundColor = .yellow
label.text = "App"
return label
}()
fileprivate let appDisplay: UILabel = {
let textView = UILabel()
textView.translatesAutoresizingMaskIntoConstraints = false
textView.backgroundColor = .cyan
textView.numberOfLines = 0
textView.font = UIFont.preferredFont(forTextStyle: .body)
return textView
}()
override func viewDidLoad() {
super.viewDidLoad()
self.setupViews()
}
fileprivate func setupViews() {
self.view.addSubview(self.scrollView)
self.scrollView.topAnchor.constraint(equalTo: self.view.safeAreaLayoutGuide.topAnchor).isActive = true
self.scrollView.bottomAnchor.constraint(equalTo: self.view.safeAreaLayoutGuide.bottomAnchor).isActive = true
self.scrollView.leftAnchor.constraint(equalTo: self.view.safeAreaLayoutGuide.leftAnchor).isActive = true
self.scrollView.rightAnchor.constraint(equalTo: self.view.safeAreaLayoutGuide.rightAnchor).isActive = true
self.scrollView.addSubview(self.contentView)
self.contentView.topAnchor.constraint(equalTo: self.scrollView.topAnchor).isActive = true
self.contentView.bottomAnchor.constraint(equalTo: self.scrollView.bottomAnchor).isActive = true
self.contentView.leftAnchor.constraint(equalTo: self.scrollView.safeAreaLayoutGuide.leftAnchor).isActive = true
self.contentView.rightAnchor.constraint(equalTo: self.scrollView.safeAreaLayoutGuide.rightAnchor).isActive = true
self.contentView.widthAnchor.constraint(equalTo: self.view.widthAnchor).isActive = true
self.contentView.addSubview(self.titleLabel)
self.titleLabel.topAnchor.constraint(equalTo: self.contentView.safeAreaLayoutGuide.topAnchor).isActive = true
self.titleLabel.leftAnchor.constraint(equalTo: self.contentView.safeAreaLayoutGuide.leftAnchor).isActive = true
self.titleLabel.rightAnchor.constraint(equalTo: self.contentView.safeAreaLayoutGuide.rightAnchor).isActive = true
self.titleLabel.heightAnchor.constraint(equalToConstant: 80).isActive = true
self.contentView.addSubview(self.appDisplay)
self.appDisplay.text = self.text + self.text + self.text + self.text + self.text + self.text + self.text + self.text + self.text + self.text + self.text + self.text + self.text
self.appDisplay.topAnchor.constraint(equalTo: self.titleLabel.safeAreaLayoutGuide.bottomAnchor, constant: 16).isActive = true
self.appDisplay.leftAnchor.constraint(equalTo: self.contentView.safeAreaLayoutGuide.leftAnchor).isActive = true
self.appDisplay.rightAnchor.constraint(equalTo: self.contentView.safeAreaLayoutGuide.rightAnchor).isActive = true
self.appDisplay.bottomAnchor.constraint(equalTo: self.contentView.safeAreaLayoutGuide.bottomAnchor).isActive = true
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment