Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //
- // WordCell.swift
- // First screen
- //
- // Created by karolis on 18/09/2019.
- // Copyright © 2019 karolis. All rights reserved.
- //
- import Foundation
- import UIKit
- class WordCell: UICollectionViewCell{
- override init(frame: CGRect) {
- super.init(frame: frame)
- setupViews()
- }
- let adressLabel: UILabel = {
- let label = UILabel()
- label.text = "DEMO GATVE 12A, Vilnius"
- label.textColor = .white
- label.font = label.font.withSize(10)
- label.translatesAutoresizingMaskIntoConstraints = false
- return label
- }()
- let distanceLabel: UILabel = {
- let label = UILabel()
- label.text = "84km"
- label.textAlignment = .right
- label.textColor = .white
- label.font = label.font.withSize(10)
- label.translatesAutoresizingMaskIntoConstraints = false
- return label
- }()
- let adressView: UIView = {
- let view = UIView()
- view.backgroundColor = .blue
- view.layer.cornerRadius = 2
- view.translatesAutoresizingMaskIntoConstraints = false
- return view
- }()
- let workIdLabel: UILabel = {
- let label = UILabel()
- label.text = "V19-074213"
- label.font = UIFont.boldSystemFont(ofSize: 14)
- label.translatesAutoresizingMaskIntoConstraints = false
- return label
- }()
- let workNameLabel: UILabel = {
- let label = UILabel()
- label.text = "test"
- label.textColor = UIColor.black.withAlphaComponent(0.5)
- label.font = label.font.withSize(12)
- label.translatesAutoresizingMaskIntoConstraints = false
- return label
- }()
- let firstStatusLabel: UILabel = {
- let label = UILabel()
- label.text = "Veluoja"
- label.backgroundColor = .red
- label.textColor = .white
- label.font = label.font.withSize(14)
- label.textAlignment = .center
- label.clipsToBounds = true
- label.layer.cornerRadius = 5
- label.translatesAutoresizingMaskIntoConstraints = false
- return label
- }()
- let secondStatusLabel: UILabel = {
- let label = UILabel()
- label.text = "2019-09-28"
- label.backgroundColor = .orange
- label.textColor = .white
- label.font = label.font.withSize(14)
- label.textAlignment = .center
- label.clipsToBounds = true
- label.layer.cornerRadius = 5
- label.translatesAutoresizingMaskIntoConstraints = false
- return label
- }()
- func setupViews(){
- addSubview(adressView)
- adressView.addSubview(adressLabel)
- adressView.addSubview(distanceLabel)
- addSubview(workIdLabel)
- addSubview(workNameLabel)
- addSubview(firstStatusLabel)
- addSubview(secondStatusLabel)
- setupConstraints()
- }
- func setupConstraints() {
- let adressBarHeight: CGFloat = 20
- let componentPadding : CGFloat = 10
- ///MARK: - BLUE BAR
- adressView.topAnchor.constraint(equalTo: topAnchor).isActive = true
- adressView.leadingAnchor.constraint(equalTo: leadingAnchor).isActive = true
- adressView.trailingAnchor.constraint(equalTo: trailingAnchor).isActive = true
- adressView.heightAnchor.constraint(equalToConstant: adressBarHeight).isActive = true
- adressLabel.topAnchor.constraint(equalTo: adressView.topAnchor).isActive = true
- adressLabel.bottomAnchor.constraint(equalTo: adressView.bottomAnchor).isActive = true
- adressLabel.leftAnchor.constraint(equalTo: adressView.leftAnchor, constant: componentPadding).isActive = true
- adressLabel.widthAnchor.constraint(equalTo: adressView.widthAnchor, multiplier: 1/2).isActive = true
- distanceLabel.topAnchor.constraint(equalTo: adressView.topAnchor).isActive = true
- distanceLabel.bottomAnchor.constraint(equalTo: adressView.bottomAnchor).isActive = true
- distanceLabel.leftAnchor.constraint(equalTo: adressLabel.rightAnchor).isActive = true
- distanceLabel.rightAnchor.constraint(equalTo: adressView.rightAnchor, constant: -componentPadding).isActive = true
- workIdLabel.topAnchor.constraint(equalTo: adressView.bottomAnchor).isActive = true
- workIdLabel.leftAnchor.constraint(equalTo: adressLabel.leftAnchor).isActive = true
- workIdLabel.widthAnchor.constraint(equalTo: widthAnchor, multiplier: 1/2).isActive = true
- workIdLabel.heightAnchor.constraint(equalToConstant: 25).isActive = true
- workNameLabel.bottomAnchor.constraint(equalTo: bottomAnchor).isActive = true
- workNameLabel.heightAnchor.constraint(equalToConstant: 20).isActive = true
- workNameLabel.leftAnchor.constraint(equalTo: workIdLabel.leftAnchor).isActive = true
- workNameLabel.rightAnchor.constraint(equalTo: rightAnchor).isActive = true
- firstStatusLabel.topAnchor.constraint(equalTo: adressView.bottomAnchor).isActive = true
- firstStatusLabel.bottomAnchor.constraint(equalTo: workIdLabel.bottomAnchor).isActive = true
- firstStatusLabel.rightAnchor.constraint(equalTo: rightAnchor).isActive = true
- firstStatusLabel.widthAnchor.constraint(equalTo: widthAnchor, multiplier: 1/6).isActive = true
- secondStatusLabel.topAnchor.constraint(equalTo: firstStatusLabel.topAnchor).isActive = true
- secondStatusLabel.bottomAnchor.constraint(equalTo: firstStatusLabel.bottomAnchor).isActive = true
- secondStatusLabel.leftAnchor.constraint(equalTo: workIdLabel.rightAnchor).isActive = true
- secondStatusLabel.rightAnchor.constraint(equalTo: firstStatusLabel.leftAnchor).isActive = true
- }
- required init?(coder aDecoder: NSCoder) {
- fatalError("init(coder:) has not been implemented")
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement