123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103 |
- //
- // PQShareSpaceHeadView.swift
- // PQSpeed
- //
- // Created by SanW on 2020/11/12.
- // Copyright © 2020 BytesFlow. All rights reserved.
- //
- import UIKit
- public class PQSectionHeadView: UIView {
- // 清除按钮回调
- public var btnClickHandle: ((_ sender: UIButton) -> Void)?
- // 是否隐藏清除按钮
- public var isHiddenClearBtn: Bool = true {
- didSet {
- clearBtn.isHidden = isHiddenClearBtn
- }
- }
- public var sectionTitle: String? {
- didSet {
- addData()
- addLayout()
- }
- }
- lazy public var lineView: UIView = {
- let lineView = UIView()
- lineView.backgroundColor = UIColor.hexColor(hexadecimal: "#EE0051")
- lineView.addCorner(corner: 1.5)
- return lineView
- }()
- lazy public var titleLab: UILabel = {
- let titleLab = UILabel()
- titleLab.textColor = UIColor.white
- titleLab.font = UIFont(name: "PingFangSC", size: 16)
- return titleLab
- }()
- lazy public var clearBtn: UIButton = {
- let clearBtn = UIButton(type: .custom)
- clearBtn.setTitle("全部已读 ", for: .normal)
- clearBtn.setImage(UIImage.init().BF_Image(named: "msg_clear_noreaded"), for: .normal)
- clearBtn.setTitleColor(UIColor.hexColor(hexadecimal: "#666666"), for: .normal)
- clearBtn.titleLabel?.font = UIFont(name: "PingFangSC", size: 13)
- clearBtn.addTarget(self, action: #selector(btnClick(sender:)), for: .touchUpInside)
- clearBtn.isHidden = true
- return clearBtn
- }()
- override public init(frame: CGRect) {
- super.init(frame: frame)
- addSubviews()
- }
- override public func layoutSubviews() {
- super.layoutSubviews()
- // addData()
- // addLayout()
- }
- required public init?(coder _: NSCoder) {
- fatalError("init(coder:) has not been implemented")
- }
- public func addSubviews() {
- addSubview(lineView)
- addSubview(titleLab)
- addSubview(clearBtn)
- }
- public func addData() {
- titleLab.text = sectionTitle
- }
- public func addLayout() {
- let lineW: CGFloat = 3
- let lineH: CGFloat = cDefaultMargin * 2
- lineView.snp.makeConstraints { make in
- make.width.equalTo(lineW)
- make.height.equalTo(lineH)
- make.centerY.equalToSuperview()
- }
- titleLab.snp.makeConstraints { make in
- make.left.equalTo(lineView.snp_right).offset(lineW * 4)
- make.centerY.equalToSuperview()
- }
- clearBtn.snp.makeConstraints { make in
- make.centerY.equalToSuperview()
- make.right.equalToSuperview().offset(-cDefaultMargin)
- }
- clearBtn.imagePosition(at: .right, space: 0)
- }
- @objc public func btnClick(sender: UIButton) {
- if btnClickHandle != nil {
- btnClickHandle!(sender)
- }
- }
- }
|