Renderings:
We in the project development process, encountered effect on the map, each write very troublesome, so this package on their own for a moment, had previously been with other people, but now they want to own package, the first attempt, hope you valuable opinion
When using relatively simple, after only need to set up a proxy, passing in the title and about two arrays can be. Because the project is swift to write, so just write a swift edition.
Because our project with the theme of the text and icons are color change, here we used a relatively simple method,
Set image of RenderingMode (after this property with iOS7), and then set tintcolor can imageView, if not this needs to be removed
leftImgView.image = UIImage(named:"ic_shouqi")?.withRenderingMode(.alwaysTemplate)
leftImgView.tintColor = UIColor(hexString: GlobalVariable.themeColor)
Other classes only need to import the two:
//
// ActivityTopShowView.swift
// QingkCloud_Swift
//
// Created by bxfMini on 2019/9/12.
//
import UIKit
protocol ActivityTopViewCellClickDelegate : NSObjectProtocol {
func deliverData(str:String,index:Int,mark:Int)
}
class ActivityTopShowView: UIView {
var isShow:Bool!
var isRightShow:Bool!
var leftImgView:UIImageView!
var rightImgView:UIImageView!
var leftBtn:UIButton!
var rightBtn:UIButton!
var leftLab:UILabel!
var rightLab:UILabel!
var leftArr:NSArray!
var rightArr:NSArray!
weak var delegate:ActivityTopViewCellClickDelegate?
override init(frame: CGRect) {
super.init(frame: frame)
isShow = false
isRightShow = false
creatUI ()
}
CREATE function () {
let lefttopView = UIView.init()
lefttopView.backgroundColor = UIColor.white
self.addSubview(lefttopView)
leftLab = UILabel.init()
leftLab.text = leftTitle
leftLab.font = UIFont.systemFont(ofSize: 15)
leftLab.textColor = UIColor (hexString: "# 666666")
lefttopView.addSubview (leftLab)
leftImgView = UIImageView.init()
leftImgView.image = UIImage(named: "ic_zhankai")
lefttopView.addSubview(leftImgView)
leftBtn = UIButton(type: .custom)
leftBtn.tag = 1
leftBtn.addTarget(self, action: #selector(btnClick(sender:)), for: .touchUpInside)
lefttopView.addSubview(leftBtn)
lefttopView.snp.makeConstraints { (make) in
make.top.left.equalTo(0)
make.width.equalTo(kScreenWidth/2)
make.height.equalTo(44)
}
leftLab.snp.makeConstraints { (make) in
make.centerY.centerX.equalTo(lefttopView)
make.width.equalTo(62)
make.height.equalTo(14)
}
leftImgView.snp.makeConstraints { (make) in
make.centerY.equalTo(lefttopView)
make.width.equalTo(10)
make.height.equalTo(6)
make.left.equalTo(leftLab.snp.right).offset(5)
}
leftBtn.snp.makeConstraints { (make) in
make.left.top.bottom.equalTo(0)
make.width.equalTo(kScreenWidth/2)
}
let righttopView = UIView.init()
righttopView.backgroundColor = UIColor.white
self.addSubview(righttopView)
rightLab = UILabel.init()
rightLab.text = rightTitle
rightLab.font = UIFont.systemFont(ofSize: 15)
rightLab.textColor = UIColor(hexString: "#666666")
righttopView.addSubview(rightLab)
rightImgView = UIImageView.init()
rightImgView.image = UIImage(named: "ic_zhankai")
righttopView.addSubview(rightImgView)
rightBtn = UIButton(type: .custom)
rightBtn.tag = 2
rightBtn.addTarget(self, action: #selector(btnClick(sender:)), for: .touchUpInside)
righttopView.addSubview(rightBtn)
righttopView.snp.makeConstraints { (make) in
make.top.right.equalTo(0)
make.width.equalTo(kScreenWidth/2)
make.height.equalTo(44)
}
rightLab.snp.makeConstraints { (make) in
make.centerY.centerX.equalTo(righttopView)
make.width.equalTo(62)
make.height.equalTo(14)
}
rightImgView.snp.makeConstraints { (make) in
make.centerY.equalTo(righttopView)
make.width.equalTo(10)
make.height.equalTo(6)
make.left.equalTo(rightLab.snp.right).offset(5)
}
rightBtn.snp.makeConstraints { (make) in
make.right.top.bottom.equalTo(0)
make.width.equalTo(kScreenWidth/2)
}
}
var leftTitle:String = "" {
didSet{
leftLab.text = leftTitle
}
}
var rightTitle:String = "" {
didSet{
rightLab.text = rightTitle
}
}
@objc func btnClick(sender:UIButton){
if sender.tag == 1 {
isRightShow = false
isShow = !isShow
if isShow{
leftImgView.image = UIImage(named:"ic_shouqi")?.withRenderingMode(.alwaysTemplate)
leftImgView.tintColor = UIColor(hexString: GlobalVariable.themeColor)
leftLab.textColor = UIColor(hexString: GlobalVariable.themeColor)
rightImgView.image = UIImage(named: "ic_zhankai")
rightLab.textColor = UIColor(hexString: "#666666")
topView.bingDingData(arr: leftArr, mark: 1)
self.superview!.addSubview(topView)
}else{
topView.removeFromSuperview()
leftImgView.image = UIImage(named: "ic_zhankai")
leftLab.textColor = UIColor (hexString: "# 666666")
}
}else{
isShow = false
isRightShow = !isRightShow
if isRightShow{
rightImgView.image = UIImage(named:"ic_shouqi")?.withRenderingMode(.alwaysTemplate)
rightImgView.tintColor = UIColor(hexString: GlobalVariable.themeColor)
rightLab.textColor = UIColor(hexString: GlobalVariable.themeColor)
leftImgView.image = UIImage(named: "ic_zhankai")
leftLab.textColor = UIColor (hexString: "# 666666")
topView.bingDingData(arr: rightArr, mark: 2)
self.superview!.addSubview(topView)
}else{
topView.removeFromSuperview()
rightImgView.image = UIImage(named: "ic_zhankai")
rightLab.textColor = UIColor(hexString: "#666666")
}
}
}
private lazy var topView:ActivityTopView = {
var topView = ActivityTopView.init(frame: CGRect(x: 0, y: 44, width: kScreenWidth, height: kScreenHeight))
topView.touchBlock = { () in
self.isShow = false
self.isRightShow = false
self.rightImgView.image = UIImage(named: "ic_zhankai")
self.rightLab.textColor = UIColor(hexString: "#666666")
self.leftImgView.image = UIImage(named: "ic_zhankai")
self.leftLab.textColor = UIColor(hexString: "#666666")
}
topView.block = {(str,index,mark) in
if self.delegate != nil{
self.delegate?.deliverData(str: str, index: index, mark: mark)
}
}
return topView
}()
required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
}
//
// ActivityTopView.swift
// QingkCloud_Swift
//
// Created by bxfMini on 2019/9/9.
//
import UIKit
class ActivityTopView: UIView,UITableViewDelegate,UITableViewDataSource {
var titleArr:NSArray!
var block:((String,Int,Int) -> Void)?
was selectIndexParh: Index Path!
was rightSelectIndexParh: Index Path!
the land: Int?
var touchBlock:(() -> Void)?
override init(frame: CGRect) {
super.init(frame: frame)
selectIndexParh = IndexPath.init(row: 0, section: 0)
rightSelectIndexParh = IndexPath.init(row: 0, section: 0)
self.addSubview(tableV)
self.backgroundColor = UIColor(r: 0, g: 0, b: 0, a: 0.6)
}
private lazy var tableV:UITableView = {
var tableView:UITableView!
tableView = UITableView.init()
tableView.delegate = self
tableView.dataSource = self
tableView.separatorStyle = UITableViewCell.SeparatorStyle.none
tableView.register(UITableViewCell.classForCoder(), forCellReuseIdentifier: NSStringFromClass(UITableViewCell.classForCoder()))
return tableView
}()
override func layoutSubviews() {
tableV.snp.makeConstraints { (make) in
make.top.left.right.equalTo(0)
make.height.equalTo(titleArr.count*44)
}
}
func bingDingData(arr:NSArray,mark:Int){
titleArr = arr
self.mark = mark
tableV.reloadData()
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return titleArr.count
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell:UITableViewCell = tableView.dequeueReusableCell(withIdentifier: NSStringFromClass(UITableViewCell.classForCoder()), for: indexPath)
cell.selectionStyle = UITableViewCell.SelectionStyle.none
if mark == 1 {
if indexPath.row == selectIndexParh.row {
cell.textLabel?.textColor = UIColor(hexString: GlobalVariable.themeColor)
}else{
cell.textLabel?.textColor = UIColor.black
}
}else{
if indexPath.row == rightSelectIndexParh.row {
cell.textLabel?.textColor = UIColor(hexString: GlobalVariable.themeColor)
}else{
cell.textLabel?.textColor = UIColor.black
}
}
cell.textLabel?.text = titleArr[indexPath.row] as? String
return cell
}
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
if mark == 1 {
if selectIndexParh == indexPath{
return
}
let newCell :UITableViewCell = tableView.cellForRow(at: indexPath)!
newCell.textLabel?.textColor = UIColor(hexString: GlobalVariable.themeColor)
let oldCell:UITableViewCell = tableView.cellForRow(at: selectIndexParh)!
oldCell.textLabel?.textColor = UIColor.black
selectIndexParh = indexPath
}else{
if rightSelectIndexParh == indexPath{
return
}
let newCell :UITableViewCell = tableView.cellForRow(at: indexPath)!
newCell.textLabel?.textColor = UIColor(hexString: GlobalVariable.themeColor)
let oldCell:UITableViewCell = tableView.cellForRow(at: rightSelectIndexParh)!
oldCell.textLabel?.textColor = UIColor.black
rightSelectIndexParh = indexPath
}
if block != nil {
block!(titleArr[indexPath.row] as! String,indexPath.row, mark!)
}
}
override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
self.removeFromSuperview()
if touchBlock != nil {
touchBlock!()
}
}
required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
}