大橙子网站建设,新征程启航
为企业提供网站建设、域名注册、服务器等服务
一、重写drawRect方法
成都创新互联公司是少有的网站建设、网站设计、营销型企业网站、小程序开发、手机APP,开发、制作、设计、买友情链接、推广优化一站式服务网络公司,从2013年成立,坚持透明化,价格低,无套路经营理念。让网页惊喜每一位访客多年来深受用户好评
二、采用CAShapeLayer方式绘制虚线
三、经济实惠型:采用贴图的方式绘制虚线(需要设计师切图配合)
在VIEW的CREAT时将你的对话框(最好是以无模式对话框模式)创建并显示: 如下代码: m_pFaceDlg = new CInterFaceDlg; //CInterFaceDlg 为你的对话框类 m_pFaceDlg-Create( IDD_DIALOG_INTERFACE, this );//IDD_DIALOG_INTERFACE为你的对话框ID。
Google地图:
我是创建了一个单例来实现google相关的东西
这个是画线的方法
这里只是画出一条线 并不是虚线
/// 画线
func addGoogleLine(mapView: T,mapLineModel:[CLLocationCoordinate2D]) - GMSPolyline{
if mapLineModel.count = 1{return GMSPolyline()}
let polyline = GMSPolyline()
linepath.removeAllCoordinates()
polyline.strokeWidth = 4
mapLineModel.forEach { (item) in
// polyline.strokeColor = UIColor.xFF3366
linepath.add(item)
}
polyline.path = linepath
polyline.geodesic = true
polyline.map = mapView
mapView.animate(with: GMSCameraUpdate.fit(GMSCoordinateBounds(coordinate: mapLineModel.first!, coordinate: mapLineModel.last!), with: UIEdgeInsets(top: 64, left: 30, bottom: 30, right: 30)))
return polyline
}
虚线需要在GMSMapViewDelegate下面这个回调中实现
func mapView(_ mapView: GMSMapView, didChange position: GMSCameraPosition) {
updateLine()
}
///设置虚线
private func updateLine() {
if self.googleMapView != nil {
let styles: [GMSStrokeStyle] = [.solidColor(UIColor.xFF3366), .solidColor(.clear)]
let scale = 1.0 / self.googleMapView!.projection.points(forMeters: 1, at: self.googleMapView!.camera.target)
let solidLine = NSNumber(value: 15.0 * Float(scale))
let gap = NSNumber(value: 10.0 * Float(scale))
if self.polyline.path != nil {
self.polyline.spans = GMSStyleSpans(self.polyline.path!, styles, [solidLine, gap], GMSLengthKind.rhumb)
}
}
}
高德地图:
需要在 MAMapViewDelegate
设置线的样式
func mapView(_ mapView: MAMapView!, rendererFor overlay: MAOverlay!) - MAOverlayRenderer! {
///画线的样式
if overlay.isKind(of: MAPolyline.self) {
let model = MAPolylineRenderer(overlay: overlay)
model?.lineWidth = 5
model?.strokeColor = UIColor.xFF3366
model?.fillColor = UIColor.x000000
model?.lineJoinType = kMALineJoinRound
model?.lineCapType = kMALineCapArrow
model?.lineDashType = .square
return model
}
return nil
}
///自己的单例方法 将多个坐标折现添加到地图上 使地图展示线段大小
func addMoreLine(mapView: MAMapView,lineCoordinates: [CLLocationCoordinate2D]) {
var coordinates = lineCoordinates
if coordinates.count = 0{ return }
if let oldMAPolyline = oldMAPolyline {
mapView.remove(oldMAPolyline)
}
let polyline = MAPolyline(coordinates: coordinates, count: UInt(lineCoordinates.count))
mapView.add(polyline)
let rect = mapView.mapRectThatFits(polyline?.boundingMapRect ?? MAMapRect(origin: MAMapPoint(x: lineCoordinates.first?.longitude ?? 0, y: lineCoordinates.first?.latitude ?? 0), size: MAMapSize(width: Double(ScreenInfo.Width), height: Double(ScreenInfo.Height - 193))))
mapView.setVisibleMapRect(rect, edgePadding: UIEdgeInsets(top: 40,left: 40,bottom: 40,right: 40), animated: true)
oldMAPolyline = polyline
}
原文: