// // TimeSelectView.swift // GeliBusinessPlatform // // Created by junye lu on 2020/4/26. // Copyright © 2020 junye lu. All rights reserved. // import UIKit protocol SendTimeSelectViewDeleagte { func SendTimeSelectViewClose() func SendTimeSelectViewSubmit(date:String) } class SendTimeSelectView: UIView,UITableViewDelegate,UITableViewDataSource { var delegate:SendTimeSelectViewDeleagte? let leftListArr = ["今天","明天","后天"] let rightListArr = ["1","2","3"] var contentView:UIView! var leftSelectIdx:Int? var rightSelectIdx:Int? @IBAction func submitAction(_ sender: Any) { delegate?.SendTimeSelectViewSubmit(date:"\(leftListArr[leftSelectIdx!]) \(rightListArr[rightSelectIdx!])") } @IBOutlet weak var rightListView: UITableView! @IBOutlet weak var leftListView: UITableView! @IBOutlet weak var bottomView: UIView! @IBAction func closeAction(_ sender: Any) { delegate?.SendTimeSelectViewClose() } func setUI(){ let maskPath = UIBezierPath(roundedRect: bottomView.bounds, byRoundingCorners:[.topLeft, .topRight], cornerRadii:CGSize(width:3, height:3)) let masklayer = CAShapeLayer() masklayer.frame = bottomView.bounds masklayer.path = maskPath.cgPath bottomView.layer.mask = masklayer leftListView.separatorStyle = .none rightListView.separatorStyle = .none leftListView.register(UINib(nibName: "OnlyLabelCell", bundle: nil), forCellReuseIdentifier: "OnlyLabel") rightListView.register(UINib(nibName: "OnlyLabelCell", bundle: nil), forCellReuseIdentifier: "OnlyLabel") tableView(leftListView, didSelectRowAt: IndexPath(row: 0, section: 0)) leftListView.reloadData() } //初始化时将xib中的view添加进来 override init(frame: CGRect) { super.init(frame: frame) contentView = loadViewFromNib() addSubview(contentView) contentView.snp.makeConstraints { (make) in make.left.top.right.bottom.equalToSuperview() } self.setUI() } // /初始化时将xib中的view添加进来 required init?(coder aDecoder: NSCoder) { super.init(coder: aDecoder) contentView = loadViewFromNib() addSubview(contentView) contentView.snp.makeConstraints { (make) in make.left.top.right.bottom.equalToSuperview() } self.setUI() } //加载xib func loadViewFromNib() -> UIView { let className = type(of: self) let bundle = Bundle(for: className) let name = NSStringFromClass(className).components(separatedBy: ".").last let nib = UINib(nibName: name!, bundle: bundle) let view = nib.instantiate(withOwner: self, options: nil).first as! UIView self.setUI() return view } //MARK: - CELL DELEGATE func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { if tableView == leftListView { return leftListArr.count } return 3 } func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat { return 49 } func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { let cell = tableView.dequeueReusableCell(withIdentifier: "OnlyLabel") as! OnlyLabelCell cell.tag = indexPath.row if tableView == leftListView { cell.titleLbl.text = leftListArr[indexPath.row] cell.titleLbl.textColor = UIColor(named: "灰色字体颜色") cell.titleLbl.font = UIFont.systemFont(ofSize: 13) cell.backgroundColor = UIColor(named: "搜索框背景色") if leftSelectIdx == indexPath.row{ cell.titleLbl.textColor = UIColor(named: "标题字颜色") cell.titleLbl.font = UIFont.boldSystemFont(ofSize: 13) cell.backgroundColor = UIColor.white } }else{ cell.titleLbl.text = rightListArr[indexPath.row] cell.titleLbl.textColor = UIColor(named: "灰色字体颜色") cell.titleLbl.font = UIFont.systemFont(ofSize: 13) if rightSelectIdx == indexPath.row{ cell.titleLbl.textColor = UIColor(named: "蓝色字体颜色") cell.titleLbl.font = UIFont.systemFont (ofSize: 13) } } return cell } func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { if tableView == leftListView { leftSelectIdx = indexPath.row rightSelectIdx = nil rightListView.reloadData() leftListView.reloadData() } if tableView == rightListView { rightSelectIdx = indexPath.row rightListView.reloadData() } } }