Skip to content

Instantly share code, notes, and snippets.

@prafullakumar
Created May 11, 2022 16:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save prafullakumar/6ec2576b1fc6469cd090384b65241fcd to your computer and use it in GitHub Desktop.
Save prafullakumar/6ec2576b1fc6469cd090384b65241fcd to your computer and use it in GitHub Desktop.
Blocks screen grab and recordings
//
// ViewController.swift
// TextField
//
// Created by Prafulla Singh on 11/5/22.
//
import UIKit
class ViewController: UIViewController {
lazy var secretBaseView: UIView? = {
let textView = UITextField()
view.addSubview(textView)
textView.translatesAutoresizingMaskIntoConstraints = false
textView.leadingAnchor.constraint(equalTo: self.view.leadingAnchor).isActive = true
textView.trailingAnchor.constraint(equalTo: self.view.trailingAnchor).isActive = true
textView.topAnchor.constraint(equalTo: self.view.topAnchor).isActive = true
textView.bottomAnchor.constraint(equalTo: self.view.bottomAnchor).isActive = true
textView.borderStyle = .none
textView.isUserInteractionEnabled = false
textView.isSecureTextEntry = true
let rootView = textView.subviews.first
return rootView
}()
override func viewDidLoad() {
super.viewDidLoad()
if let view = secretBaseView {
//Image View
let imageView = UIImageView()
imageView.heightAnchor.constraint(equalToConstant: 120.0).isActive = true
imageView.widthAnchor.constraint(equalToConstant: 120.0).isActive = true
imageView.image = UIImage(systemName: "doc.fill")
//Text Label
let label = UILabel(frame: CGRect(x: 0, y: 0, width: 200, height: 21))
label.center = CGPoint(x: 160, y: 285)
label.textAlignment = .center
label.text = "I'm a test label"
// Button
let button = UIButton(frame: CGRect(x: 100, y: 100, width: 100, height: 50))
button.backgroundColor = .gray
button.setTitle("Test Button", for: .normal)
button.addTarget(self, action: #selector(buttonAction), for: .touchUpInside)
//Stack View
let stackView = UIStackView()
stackView.axis = NSLayoutConstraint.Axis.vertical
stackView.distribution = UIStackView.Distribution.equalSpacing
stackView.alignment = UIStackView.Alignment.center
stackView.spacing = 16.0
stackView.addArrangedSubview(imageView)
stackView.addArrangedSubview(label)
stackView.addArrangedSubview(button)
stackView.translatesAutoresizingMaskIntoConstraints = false
view.addSubview(stackView)
//Constraints
stackView.centerXAnchor.constraint(equalTo: view.centerXAnchor).isActive = true
stackView.centerYAnchor.constraint(equalTo: view.centerYAnchor).isActive = true
}
}
@objc func buttonAction(sender: UIButton!) {
print("Button tapped")
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment