如何移除MKPointAnnotation的3D效果,实现纯色扁平化标记
移除MKPointAnnotation的3D效果,实现纯色扁平化标记
效果对比
- 当前带3D效果(阴影/渐变)的标记

- 目标:纯色扁平化标记

当前实现代码
已通过以下函数成功修改标记颜色,可在此基础上调整实现扁平化:
func mapView(_ mapView: MKMapView, viewFor annotation: MKAnnotation) -> MKAnnotationView? { let annotationView = MKMarkerAnnotationView(annotation: annotation, reuseIdentifier: "MyMarker") annotationView.markerTintColor = UIColor.blue return annotationView }
当前修改颜色后的标记效果
实现方案
只需在现有代码中添加几个属性设置,即可移除3D效果,得到纯色扁平化标记:
func mapView(_ mapView: MKMapView, viewFor annotation: MKAnnotation) -> MKAnnotationView? { let annotationView = MKMarkerAnnotationView(annotation: annotation, reuseIdentifier: "MyMarker") annotationView.markerTintColor = UIColor.blue // 开启扁平化模式,移除默认的3D渐变质感 annotationView.isFlat = true // 移除阴影(可选,根据需求决定是否保留) annotationView.shadowOpacity = 0 // 隐藏标记内的默认图标/文字(可选,让样式更简洁) annotationView.glyphVisibility = .hidden return annotationView }
关键属性说明
isFlat = true:MKMarkerAnnotationView的专属属性,开启后直接切换为纯色扁平样式,去掉默认的渐变和立体效果。shadowOpacity = 0:完全移除标记的阴影,进一步强化扁平化视觉。glyphVisibility = .hidden:如果不需要标记内部的图标或文字,隐藏后标记样式更纯粹。
内容的提问来源于stack exchange,提问作者MirrorJacket123
相关产品推荐
相关产品推荐

