Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var collectionView: UICollectionView!
- var titleLabel: UILabel!
- override func viewDidLoad() {
- super.viewDidLoad()
- // Do any additional setup after loading the view, typically from a nib.
- self.view.translatesAutoresizingMaskIntoConstraints = false
- let margins = self.view.layoutMarginsGuide
- let layout: UICollectionViewFlowLayout = UICollectionViewFlowLayout()
- layout.sectionInset = UIEdgeInsets(top: 20, left: 10, bottom: 10, right: 10)
- collectionView = UICollectionView(frame: self.view.frame, collectionViewLayout: layout)
- layout.itemSize = CGSize(width: self.collectionView.frame.width / 4, height: self.collectionView.frame.width / 4)
- layout.minimumInteritemSpacing = self.collectionView.frame.width / 15
- layout.minimumLineSpacing = self.collectionView.frame.width / 5
- collectionView.backgroundColor = UIColor.black
- collectionView.dataSource = self
- collectionView.delegate = self
- collectionView.register(UICollectionViewCell.self, forCellWithReuseIdentifier: "Cell")
- titleLabel = UILabel()
- titleLabel.translatesAutoresizingMaskIntoConstraints = false
- titleLabel.textAlignment = .center
- titleLabel.numberOfLines = 1
- titleLabel.font = UIFont.systemFont(ofSize: 22)
- titleLabel.backgroundColor = UIColor.lightGray
- titleLabel.text = "Challenges"
- titleLabel.textColor = UIColor.red
- let stackView = UIStackView(arrangedSubviews: [titleLabel, collectionView])
- stackView.backgroundColor = UIColor.white
- stackView.axis = .vertical
- stackView.distribution = .fillEqually
- stackView.alignment = .fill
- stackView.spacing = 5
- self.view.addSubview(stackView)
- stackView.translatesAutoresizingMaskIntoConstraints = false
- //stackView.centerXAnchor.constraint(equalTo: self.view.centerXAnchor).isActive = true
- //stackView.centerYAnchor.constraint(equalTo: self.view.centerYAnchor).isActive = true
- stackView.topAnchor.constraint(equalTo: self.view.topAnchor).isActive = true
- stackView.leadingAnchor.constraint(equalTo: self.view.leadingAnchor).isActive = true
- stackView.trailingAnchor.constraint(equalTo: self.view.trailingAnchor).isActive = true
- stackView.bottomAnchor.constraint(equalTo: self.view.bottomAnchor).isActive = true
- stackView.heightAnchor.constraint(equalTo: self.view.heightAnchor, multiplier: 1.0).isActive = true
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement