jsdw_ios/QuickLocation/Section/Web/Controller/NavigationTitleView.swift

67 lines
2.1 KiB
Swift

//
// NavigationTitleView.swift
// PaiLiBo
//
// Created by SeanXu on 2019/7/9.
// Copyright © 2019 DemoOrg. All rights reserved.
//
import UIKit
import SnapKit
class NavigationTitleView: UIView {
let titleLabel = UILabel(frame: .zero)
let imageView = UIImageView(frame: .zero)
let spacingView = UIView(frame: .zero)
override var intrinsicContentSize: CGSize {
return UIView.layoutFittingExpandedSize
}
override init(frame: CGRect) {
super.init(frame: frame)
let stackView = UIStackView(arrangedSubviews: [titleLabel, imageView])
stackView.alignment = .center
stackView.spacing = 4.0
titleLabel.font = UIFont.systemFont(ofSize: 18, weight: .bold)
titleLabel.textColor = UIColor.black
titleLabel.setContentCompressionResistancePriority(.defaultLow, for: .horizontal)
titleLabel.setContentHuggingPriority(.defaultLow, for: .horizontal)
imageView.setContentCompressionResistancePriority(.defaultHigh, for: .horizontal)
imageView.setContentHuggingPriority(.defaultHigh, for: .horizontal)
let contentView = UIView(frame: .zero)
addSubview(spacingView)
addSubview(contentView)
contentView.addSubview(stackView)
spacingView.snp.makeConstraints { make in
make.left.top.bottom.equalToSuperview()
make.width.equalTo(0)
}
contentView.snp.makeConstraints { make in
make.left.equalTo(spacingView.snp.right)
make.top.bottom.right.equalToSuperview()
}
stackView.snp.makeConstraints { make in
make.left.greaterThanOrEqualToSuperview()
make.right.lessThanOrEqualToSuperview()
make.top.bottom.equalToSuperview()
make.center.equalToSuperview()
}
}
required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
func configure(spacing: CGFloat) {
spacingView.snp.updateConstraints { make in
make.width.equalTo(spacing)
}
layoutIfNeeded()
}
}