宽窄优行-由【嘉易行】项目成品而来
younger_times
2023-07-05 0d8f5fc8a516bfd07e425909e4a4432600572ee7
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
//
//  UserCalloutView.swift
//  QuanKeTong
//
//  Created by alvin_y on 2019/6/13.
//  Copyright © 2019 yang-wang. All rights reserved.
//
 
import UIKit
 
class UserCalloutView: UIView {
 
    @IBOutlet weak var view_bg: UIView!
    
    @IBOutlet weak var lb_name: UILabel!
    
    
    /// 着色
    var yy_tintColor = UIColor.color(hexString: "#333333")
    
    /// 字体
    var yy_font = UIFont.systemFont(ofSize: 12)
    
    /// 着色
    var yy_isTintColor = false
    
    /// 赋值标题
    var title: String = ""{
        didSet{
            if yy_isTintColor{
                let mutableString = NSMutableAttributedString.init()
                // 判断是否是数字
                for item in title{
                    let pred = NSPredicate(format: "SELF MATCHES %@", "[0-9:]*")
                    if pred.evaluate(with: item.string){
                        mutableString.append(NSAttributedString.init(string: item.string, attributes: [NSAttributedString.Key.foregroundColor: yy_tintColor,NSAttributedString.Key.font: yy_font]))
                    }else{
                        mutableString.append(NSAttributedString.init(string: item.string, attributes: [NSAttributedString.Key.font: yy_font]))
                    }
                    self.lb_name.attributedText = mutableString
                }
            }else{
                self.lb_name.text = title
                self.lb_name.font = yy_font
            }
        }
    }
    
    class func instance() -> UserCalloutView {
        let v = UINib(nibName: "UserCalloutView", bundle: nil).instantiate(withOwner: self, options: nil).first as! UserCalloutView
        return v
    }
    
}