2016-03-28 65 views
0

嘿,我一直在寻找这个答案,但似乎无法找到任何哈哈。所以我在看的是添加一个UIWebView MKPinAnnotationView.detailCalloutAccessoryView,以便我可以使用HTML来做一些格式。但它不能正常工作。看到我的代码如下。添加UIWebView MKPinAnnotationView.detailCalloutAccessoryView

view = MKPinAnnotationView(annotation: annotation, reuseIdentifier: identifier) 
view.canShowCallout = true 
view.calloutOffset = CGPoint(x: -5, y: 5) 

let detailView = UIWebView() 
let poi = annotation as POI 

var htmlString: String = "<html><body><p>" 
htmlString = htmlString + "<b><font size = \"3\">" + poi.title! + "</font></b><br>" 
htmlString = htmlString + "Number of Reviews: " + String(poi.review_count) + "<br>" 
htmlString = htmlString + "</p></body></html>" 

detailView.loadHTMLString(htmlString, baseURL: nil) 
view.detailCalloutAccessoryView = detailView 

我得到的结果是这样的。

enter image description here

只有标题显示出来,这也是我认为来自MKAnnotation.title,而不是我的UIWebView。有没有人遇到过这个问题?谢谢!

回答

0

您正在将UIWebView添加到detailCalloutAccessoryView,但您并未为您设置框架UIWebView实例。试着做下面的事。

let detailView = UIWebView() 
detailView.frame = CGRectMake(0, 0, 200, 200) //set your custom height and width 

这应该添加UIWebViewdetailCalloutAccessoryView