Last active
July 5, 2019 06:41
-
-
Save tuzaiz/2e74bcae6471004bf4a31246d99a8ed3 to your computer and use it in GitHub Desktop.
Fit Content Size UITextView
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import UIKit | |
import PlaygroundSupport | |
class MyViewController : UIViewController { | |
override func loadView() { | |
let view = UIView() | |
view.backgroundColor = .white | |
let textView = UITextView() | |
textView.backgroundColor = UIColor.lightGray | |
textView.translatesAutoresizingMaskIntoConstraints = false | |
textView.isScrollEnabled = false | |
textView.text = """ | |
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum. | |
""" | |
view.addSubview(textView) | |
textView.topAnchor.constraint(equalTo: view.topAnchor, constant: 88.0).isActive = true | |
textView.leadingAnchor.constraint(equalTo: view.leadingAnchor, constant: 16.0).isActive = true | |
textView.trailingAnchor.constraint(equalTo: view.trailingAnchor, constant: -16.0).isActive = true | |
self.view = view | |
} | |
} | |
// Present the view controller in the Live View window | |
PlaygroundPage.current.liveView = MyViewController() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment