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 73 74 75 76 77 78 79
| import Foundation import MapKit public class MyAnnotation : MKAnnotationView { var rectangoView:UIView!; var lblTitle:UILabel!; var lblIcon:UILabel!; var circleView:UIView!; var triangle:UIView!; var DrawView:UIView!; override init(annotation: MKAnnotation!, reuseIdentifier: String!) { super.init(annotation: annotation, reuseIdentifier: reuseIdentifier); lblTitle = UILabel(); lblIcon = UILabel(); rectangoView = UIView(); circleView = UIView();
circleView.addSubview(lblIcon); rectangoView.addSubview(lblTitle) rectangoView.addSubview(circleView);
let path:UIBezierPath = UIBezierPath (); path.moveToPoint(CGPoint(x: 0, y: 0)); path.addLineToPoint(CGPoint(x: 10, y: 10)); path.addLineToPoint(CGPoint(x: 20, y: 0)); path.addLineToPoint(CGPoint(x: 0, y: 0));
let masklayer:CAShapeLayer = CAShapeLayer (); masklayer.path = path.CGPath; triangle = UIView(frame: CGRect(x: 22, y: 28, width: 20, height: 20)); triangle.layer.mask = masklayer; DrawView = UIView(); DrawView.addSubview(rectangoView); DrawView.addSubview(triangle); self.addSubview(DrawView); }
public required init(coder aDecoder: NSCoder) { super.init(coder: aDecoder); } override init(frame: CGRect) { super.init(frame: frame); } public func DrawCustomerView() { lblTitle.text = "5200萬"; lblTitle.textColor = UIColor.whiteColor(); lblTitle.font = UIFont.systemFontOfSize(12); lblTitle.frame.origin.x = 24; lblTitle.frame.origin.y = 7; lblTitle.sizeToFit(); rectangoView.frame = CGRect(x: 0, y: 0, width: lblTitle.frame.width + 30, height: 28); rectangoView.backgroundColor = UIColor(red: 0.208, green:0.596 , blue: 0.859, alpha: 1); rectangoView.layer.cornerRadius = 3; lblIcon.font = UIFont.systemFontOfSize(11); lblIcon.font = UIFont.boldSystemFontOfSize(14); lblIcon.text = "成"; lblIcon.textColor = rectangoView.backgroundColor; lblIcon.sizeToFit(); lblIcon.center = CGPoint (x: 10, y: 10); circleView.frame = CGRect(x: 2, y: 4, width: 20, height: 20); circleView.backgroundColor = UIColor.whiteColor(); circleView.layer.cornerRadius = 10; circleView.alpha = 1; triangle.backgroundColor = UIColor(red: 0.208, green:0.596 , blue: 0.859, alpha: 1); DrawView.frame = CGRect(x: 0, y: 0, width:triangle.frame.width,height: 48); self.frame = CGRect(x: 0, y: 0, width: rectangoView.frame.width, height: rectangoView.frame.height); self.centerOffset = CGPoint(x: 0, y: -21); } }
|