//
|
// CarpoolingAnnotationView.swift
|
// OKProject
|
//
|
// Created by 无故事王国 on 2022/5/24.
|
// Copyright © 2022 yangwang. All rights reserved.
|
//
|
|
import UIKit
|
|
class CarpoolingAnnotationView: MAAnnotationView {
|
|
var calloutView:CalloutView?
|
|
override init!(annotation: MAAnnotation!, reuseIdentifier: String!) {
|
super.init(annotation: annotation, reuseIdentifier: reuseIdentifier)
|
}
|
|
|
required init?(coder aDecoder: NSCoder) {
|
fatalError("init(coder:) has not been implemented")
|
}
|
|
override func setSelected(_ selected: Bool, animated: Bool) {
|
if self.isSelected == selected{return}
|
if selected{
|
if self.calloutView == nil{
|
self.calloutView = CalloutView()
|
}
|
addSubview(self.calloutView!)
|
self.calloutView!.center = CGPoint(x: 8, y: 0)
|
}
|
|
super.setSelected(selected, animated: animated)
|
}
|
|
func setText(_ text:String){
|
calloutView?.titleLabel.text = " \(text) "
|
}
|
|
}
|
|
class CalloutView:UIView{
|
var titleLabel : UILabel!
|
|
override init(frame: CGRect) {
|
super.init(frame: frame)
|
initSubViews()
|
}
|
|
required init?(coder aDecoder: NSCoder) {
|
super.init(coder: aDecoder)
|
initSubViews()
|
}
|
|
func initSubViews() {
|
backgroundColor = UIColor.clear
|
// 添加标题,即商户名
|
titleLabel = UILabel()
|
titleLabel.font = UIFont.systemFont(ofSize: 14)
|
titleLabel.textColor = .black
|
titleLabel.textAlignment = .center
|
titleLabel.backgroundColor = .white
|
titleLabel.cornerRadius = 16
|
titleLabel.maskToBounds = true
|
addSubview(titleLabel)
|
titleLabel.snp.makeConstraints { make in
|
make.center.equalToSuperview().inset(UIEdgeInsets(top: -45, left: 0, bottom: 0, right: 0))
|
make.height.equalTo(32)
|
}
|
}
|
}
|