2016-03-28 66 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