宽窄优行-由【嘉易行】项目成品而来
younger_times
2023-04-06 a1ae6802080a22e6e6ce6d0935e95facb1daca5c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
//
//  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)
        }
    }
}