improved constraints to center align as requested by design

This commit is contained in:
Kevin G Christiano 2020-04-07 14:10:32 -04:00
parent d9337cadff
commit f125d55962
2 changed files with 26 additions and 12 deletions

View File

@ -15,7 +15,7 @@ open class DoughnutChart: View {
//--------------------------------------------------
public var doughnutLayer = CALayer()
public var titleLabel = Label.createLabelRegularTitleLarge(true)
public var titleLabel = Label.createLabelBoldTitleLarge(true)
public var subTitleLabel = Label.createLabelRegularMicro(true)
public var labelContainer = View()
public static let heightConstant: CGFloat = 136
@ -49,6 +49,22 @@ open class DoughnutChart: View {
}
}
//--------------------------------------------------
// MARK: - Initializers
//--------------------------------------------------
public override init(frame: CGRect) {
super.init(frame: .zero)
}
public convenience init() {
self.init(frame: .zero)
}
public required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
//--------------------------------------------------
// MARK: - Lifecycle
//--------------------------------------------------

View File

@ -28,35 +28,33 @@ import Foundation
open override func setupView() {
super.setupView()
doughnutChart.translatesAutoresizingMaskIntoConstraints = false
addSubview(doughnutChart)
colorLablesStack.translatesAutoresizingMaskIntoConstraints = false
addSubview(colorLablesStack)
doughnutChart.leadingAnchor.constraint(equalTo: leadingAnchor).isActive = true
doughnutChart.topAnchor.constraint(equalTo: topAnchor).isActive = true
doughnutChart.topAnchor.constraint(greaterThanOrEqualTo: topAnchor).isActive = true
bottomAnchor.constraint(greaterThanOrEqualTo: doughnutChart.bottomAnchor).isActive = true
let doughnutBottomAnchor = bottomAnchor.constraint(equalTo: doughnutChart.bottomAnchor)
doughnutBottomAnchor.priority = UILayoutPriority(rawValue: 200)
doughnutBottomAnchor.isActive = true
bottomAnchor.constraint(greaterThanOrEqualTo: colorLablesStack.bottomAnchor).isActive = true
let colorLablesBottomAnchor = bottomAnchor.constraint(equalTo: colorLablesStack.bottomAnchor)
colorLablesBottomAnchor.priority = UILayoutPriority(rawValue: 204)
colorLablesBottomAnchor.isActive = true
let colorLablesTopAnchor = colorLablesStack.topAnchor.constraint(equalTo: doughnutChart.topAnchor)
colorLablesStack.topAnchor.constraint(greaterThanOrEqualTo: topAnchor).isActive = true
let colorLablesTopAnchor = colorLablesStack.topAnchor.constraint(equalTo: topAnchor)
colorLablesTopAnchor.priority = .defaultLow
colorLablesTopAnchor.isActive = true
colorLablesStack.topAnchor.constraint(greaterThanOrEqualTo: doughnutChart.topAnchor).isActive = true
bottomAnchor.constraint(greaterThanOrEqualTo: colorLablesStack.bottomAnchor).isActive = true
trailingAnchor.constraint(equalTo: colorLablesStack.trailingAnchor).isActive = true
let centerY = colorLablesStack.centerYAnchor.constraint(equalTo: doughnutChart.centerYAnchor)
centerY.priority = UILayoutPriority(rawValue: 500)
centerY.isActive = true
doughnutChart.centerYAnchor.constraint(equalTo: colorLablesStack.centerYAnchor).isActive = true
colorLablesStack.leadingAnchor.constraint(equalTo: doughnutChart.trailingAnchor, constant: PaddingThree).isActive = true
colorLablesStack.backgroundColor = .clear
}