77 lines
2.8 KiB
Swift
77 lines
2.8 KiB
Swift
//
|
|
// RadioButtonWithLabel.swift
|
|
// MVMCoreUI
|
|
//
|
|
// Created by Suresh, Kamlesh on 10/21/19.
|
|
// Copyright © 2019 Verizon Wireless. All rights reserved.
|
|
//
|
|
|
|
import UIKit
|
|
|
|
@objcMembers public class RadioButtonLabel: View {
|
|
|
|
public let radioButton = RadioButton()
|
|
var delegateObject: MVMCoreUIDelegateObject?
|
|
let label = Label()
|
|
|
|
// MARK: - Inits
|
|
public init() {
|
|
super.init(frame: .zero)
|
|
}
|
|
|
|
public override init(frame: CGRect) {
|
|
super.init(frame: frame)
|
|
}
|
|
|
|
required public init?(coder aDecoder: NSCoder) {
|
|
super.init(coder: aDecoder)
|
|
}
|
|
|
|
public override func updateView(_ size: CGFloat) {
|
|
super.updateView(size)
|
|
radioButton.updateView(size)
|
|
label.updateView(size)
|
|
}
|
|
|
|
open override func setupView() {
|
|
super.setupView()
|
|
guard subviews.count == 0 else {
|
|
return
|
|
}
|
|
|
|
addSubview(radioButton)
|
|
radioButton.leftAnchor.constraint(equalTo: layoutMarginsGuide.leftAnchor, constant: 0).isActive = true
|
|
radioButton.topAnchor.constraint(greaterThanOrEqualTo: layoutMarginsGuide.topAnchor, constant: PaddingOne).isActive = true
|
|
layoutMarginsGuide.bottomAnchor.constraint(greaterThanOrEqualTo: radioButton.bottomAnchor, constant: PaddingOne).isActive = true
|
|
radioButton.centerYAnchor.constraint(equalTo: layoutMarginsGuide.centerYAnchor).isActive = true
|
|
|
|
if let rightView = createRightView() {
|
|
addSubview(rightView)
|
|
rightView.leftAnchor.constraint(equalTo: radioButton.rightAnchor, constant: PaddingHorizontalBetweenRelatedItems).isActive = true
|
|
rightView.rightAnchor.constraint(equalTo: layoutMarginsGuide.rightAnchor, constant: 0).isActive = true
|
|
|
|
var constraint = rightView.topAnchor.constraint(greaterThanOrEqualTo: layoutMarginsGuide.topAnchor, constant: PaddingOne)
|
|
constraint.priority = .defaultHigh
|
|
constraint.isActive = true
|
|
|
|
constraint = layoutMarginsGuide.bottomAnchor.constraint(greaterThanOrEqualTo: rightView.bottomAnchor, constant: PaddingOne)
|
|
constraint.priority = .defaultHigh
|
|
constraint.isActive = true
|
|
layoutMarginsGuide.centerYAnchor.constraint(equalTo: rightView.centerYAnchor).isActive = true
|
|
}
|
|
}
|
|
|
|
func createRightView() -> ViewConstrainingView? {
|
|
let rightView = ViewConstrainingView(constrainingView: label)
|
|
return rightView
|
|
}
|
|
|
|
open override func set(with model: MoleculeModelProtocol, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [AnyHashable: Any]?) {
|
|
guard let radioButtonLabelModel = model as? RadioButtonLabelModel else { return }
|
|
|
|
radioButton.set(with: radioButtonLabelModel.radioButton, delegateObject, additionalData)
|
|
label.set(with: radioButtonLabelModel.label, delegateObject, additionalData)
|
|
}
|
|
|
|
}
|