Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- struct SubscriptionButtonViewModel {
- let pediodText: String
- let priceText: String
- let backgroundColor: UIColor
- let textColor: UIColor
- let borderColor: UIColor?
- }
- class SubscriptionButtonView: UIButton {
- private enum Constants {
- static let basicFont: UIFont = UIFont.fontRobotoBoldOf(size: 20)
- static let cornerRadius: CGFloat = 4.0
- static let defaultBordedWidth: CGFloat = 1.5
- }
- enum ViewConstants {
- static let defaultButtonHeight: CGFloat = 60.0
- }
- private weak var pediodLabel: UILabel!
- private weak var priceLabel: UILabel!
- class func create(with model: SubscriptionButtonViewModel) -> SubscriptionButtonView {
- let view = SubscriptionButtonView()
- view.configure(with: model)
- return view
- }
- }
- private extension SubscriptionButtonView {
- func createPeriodLabel(with model: SubscriptionButtonViewModel) -> UILabel {
- let label = UILabel()
- label.textColor = model.textColor
- label.font = Constants.basicFont
- label.text = model.pediodText
- label.textAlignment = .left
- label.translatesAutoresizingMaskIntoConstraints = false
- addSubview(label)
- label.leadingAnchor.constraint(equalTo: leadingAnchor, constant: 20).isActive = true
- label.centerYAnchor.constraint(equalTo: centerYAnchor).isActive = true
- return label
- }
- func createPriceLabel(with model: SubscriptionButtonViewModel) -> UILabel {
- let label = UILabel()
- label.textColor = model.textColor
- label.font = Constants.basicFont
- label.text = model.priceText
- label.textAlignment = .right
- label.translatesAutoresizingMaskIntoConstraints = false
- addSubview(label)
- label.trailingAnchor.constraint(equalTo: trailingAnchor, constant: -20).isActive = true
- label.centerYAnchor.constraint(equalTo: centerYAnchor).isActive = true
- return label
- }
- func createViews(with model: SubscriptionButtonViewModel) {
- pediodLabel = createPeriodLabel(with: model)
- priceLabel = createPriceLabel(with: model)
- backgroundColor = model.backgroundColor
- layer.cornerRadius = Constants.cornerRadius
- clipsToBounds = true
- if let borderColor = model.borderColor {
- layer.borderColor = borderColor.cgColor
- layer.borderWidth = Constants.defaultBordedWidth
- }
- translatesAutoresizingMaskIntoConstraints = false
- }
- func configure(with model: SubscriptionButtonViewModel) {
- createViews(with: model)
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement