Skip to content

Instantly share code, notes, and snippets.

@jeremiegirault
Created May 30, 2017 15:14
Show Gist options
  • Save jeremiegirault/c0cebd75d7dfe2342f84e4ecda18c6b5 to your computer and use it in GitHub Desktop.
Save jeremiegirault/c0cebd75d7dfe2342f84e4ecda18c6b5 to your computer and use it in GitHub Desktop.
//: [Previous](@previous)
import UIKit
import PlaygroundSupport
let view = UIView(frame: CGRect(x: 0, y: 0, width: 200, height: 400))
var test: Bool = false
class Handler: NSObject {
@objc func onTap() {
// how to perform an animation of the label frame according to it's content ?
UIView.animate(withDuration: 1) {
bottomLabel.text = test ? "Hello\nHello\nHello" : "Hello"
}
test = !test
}
}
let handler = Handler()
view.addGestureRecognizer(UITapGestureRecognizer(target: handler, action: #selector(Handler.onTap)))
let bottomLabel = UILabel()
bottomLabel.backgroundColor = .green
bottomLabel.numberOfLines = 0
bottomLabel.text = "Hello"
let topLabel = UILabel()
topLabel.backgroundColor = .purple
topLabel.text = "Always top"
let stackView = UIStackView()
stackView.translatesAutoresizingMaskIntoConstraints = false
stackView.axis = .vertical
stackView.alignment = .center
stackView.addArrangedSubview(topLabel)
stackView.addArrangedSubview(bottomLabel)
view.addSubview(stackView)
view.backgroundColor = .red
NSLayoutConstraint.activate([
stackView.leadingAnchor.constraint(equalTo: view.leadingAnchor),
stackView.trailingAnchor.constraint(equalTo: view.trailingAnchor),
stackView.bottomAnchor.constraint(equalTo: view.bottomAnchor),
])
PlaygroundPage.current.liveView = view
//: [Next](@next)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment