作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一个带有显示标题和副标题的注释的 map View 。字幕有时比注释的宽度长,所以我想知道是否可以使它们成为多行?到目前为止,它的编码如下:
func annotate(newCoordinate, title: String, subtitle: String) {
let annotation = MKPointAnnotation()
annotation.coordinate = newCoordinate
annotation.title = title
annotation.subtitle = subtitle
self.map.addAnnotation(annotation)
}
然后我设置了一些选项
func mapView(mapView: MKMapView, viewForAnnotation annotation: MKAnnotation) -> MKAnnotationView? {...}
这与这里无关。
是否可以制作自定义注释 View ?我尝试了几件事,但没有任何效果。我能得到的最接近的是添加一个按钮来单独显示较长的字幕,但我宁愿将其放在注释中。
可能吗?
最佳答案
我想通了,我在 viewForAnnotation 中添加了一个标签,它就起作用了
́\_(ツ)_/́
func mapView(mapView: MKMapView, viewForAnnotation annotation: MKAnnotation) -> MKAnnotationView? {
if annotation is MKUserLocation {
//return nil so map view draws "blue dot" for standard user location
return nil
}
let reuseId = "pin"
var pinView = mapView.dequeueReusableAnnotationViewWithIdentifier(reuseId) as? MKPinAnnotationView
if pinView == nil {
pinView = MKPinAnnotationView(annotation: annotation, reuseIdentifier: reuseId)
pinView!.canShowCallout = true
}
else {
pinView!.annotation = annotation
}
//THIS IS THE GOOD BIT
let subtitleView = UILabel()
subtitleView.font = subtitleView.font.fontWithSize(12)
subtitleView.numberOfLines = 0
subtitleView.text = annotation.subtitle!
pinView!.detailCalloutAccessoryView = subtitleView
return pinView
}
关于ios - MapView 注释中的较长字幕(swift),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46970581/
我对如何在 Typescript 中对 API 进行建模有点困惑。 我正在尝试对 hexo 进行建模API,例如用法,看起来有点像这样: hexo.extend.tag.register(name,
我是一名优秀的程序员,十分优秀!