Skip to content

Instantly share code, notes, and snippets.

@Tavernari
Last active November 20, 2020 19:06
Show Gist options
  • Save Tavernari/a35e2155735429723fb941d93c21869e to your computer and use it in GitHub Desktop.
Save Tavernari/a35e2155735429723fb941d93c21869e to your computer and use it in GitHub Desktop.
TransformView ViewCode
import UIKit
class TransformView: UIView {
var inputTextField: UITextField!
var transformButton: UIButton!
private func makeInputTextField() -> UITextField {
let input = UITextField()
input.textColor = .label
input.placeholder = "Add only letters here"
input.textAlignment = .center
input.layer.borderColor = UIColor.darkGray.cgColor
input.layer.borderWidth = 1
input.layer.cornerRadius = 8
input.translatesAutoresizingMaskIntoConstraints = false
return input
}
private func makeButton() -> UIButton {
let button = UIButton()
button.setTitleColor(.secondaryLabel, for: .normal)
button.setTitle("Transform", for: .normal)
button.translatesAutoresizingMaskIntoConstraints = false
return button
}
func make() -> Self {
backgroundColor = .systemBackground
inputTextField = makeInputTextField()
addSubview(inputTextField)
transformButton = makeButton()
addSubview(transformButton)
inputTextField
.centerYAnchor
.constraint(equalTo: centerYAnchor)
.isActive = true
inputTextField
.centerXAnchor
.constraint(equalTo: centerXAnchor)
.isActive = true
inputTextField
.widthAnchor
.constraint(equalToConstant: 200)
.isActive = true
inputTextField
.heightAnchor
.constraint(equalToConstant: 30)
.isActive = true
transformButton
.topAnchor
.constraint(equalTo: inputTextField.bottomAnchor,
constant: 40)
.isActive = true
transformButton
.centerXAnchor
.constraint(equalTo: inputTextField.centerXAnchor)
.isActive = true
return self
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment