Skip to content

Instantly share code, notes, and snippets.

@giln
Created May 6, 2019 09:03
Show Gist options
  • Save giln/5780ebfb67180ebb64cc24ade47b996e to your computer and use it in GitHub Desktop.
Save giln/5780ebfb67180ebb64cc24ade47b996e to your computer and use it in GitHub Desktop.
import PlaygroundSupport
import UIKit
@testable import MVCMovieInfoFramework
open class ImageWithFourLabelView: UIView {
// MARK: - Variables
private let horizontalStackView = UIStackView()
private let verticalStackView = UIStackView()
public let imageView = DownloadImageView()
public let firstLabel = UILabel()
public let secondLabel = UILabel()
public let thirdLabel = UILabel()
public let fourthLabel = UILabel()
// MARK: - Lifecycle
public override init(frame: CGRect) {
super.init(frame: frame)
commonInit()
}
public required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
commonInit()
}
// MARK: - Private
private func commonInit() {
backgroundColor = UIColor.white
firstLabel.font = UIFont.preferredFont(forTextStyle: .headline)
firstLabel.adjustsFontForContentSizeCategory = true
secondLabel.numberOfLines = 3
thirdLabel.font = UIFont.preferredFont(forTextStyle: .footnote)
thirdLabel.adjustsFontForContentSizeCategory = true
verticalStackView.axis = .vertical
verticalStackView.distribution = .fill
verticalStackView.alignment = .leading
verticalStackView.spacing = 10
horizontalStackView.axis = .horizontal
horizontalStackView.distribution = .fill
horizontalStackView.alignment = .center
horizontalStackView.spacing = 20
horizontalStackView.preservesSuperviewLayoutMargins = true
horizontalStackView.isLayoutMarginsRelativeArrangement = true
addSubview(horizontalStackView)
horizontalStackView.anchor(in: self)
horizontalStackView.addArrangedSubview(imageView)
horizontalStackView.addArrangedSubview(verticalStackView)
imageView.widthAnchor.constraint(equalToConstant: 90).isActive = true
imageView.heightAnchor.constraint(equalToConstant: 120).isActive = true
imageView.backgroundColor = UIColor.black
verticalStackView.addArrangedSubview(firstLabel)
verticalStackView.addArrangedSubview(secondLabel)
verticalStackView.addArrangedSubview(thirdLabel)
verticalStackView.addArrangedSubview(fourthLabel)
}
}
let view = ImageWithFourLabelView(frame: CGRect(x: 0, y: 0, width: 375, height: 150))
view.firstLabel.text = "Title"
view.secondLabel.text = "Description"
view.thirdLabel.text = "Date"
view.fourthLabel.text = "⭐️"
PlaygroundPage.current.liveView = view
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment