Created
May 30, 2017 15:14
-
-
Save jeremiegirault/c0cebd75d7dfe2342f84e4ecda18c6b5 to your computer and use it in GitHub Desktop.
This file contains 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
//: [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