我有很長的MKannotationView標題文本。有沒有一種簡單的方法可以讓標題的文字大小合適?Swift:MKAnnotation長標題文本
reuseId = "Pin"
var pinView = mapView.dequeueReusableAnnotationViewWithIdentifier(reuseId)
pinView = MKAnnotationView(annotation: annotation, reuseIdentifier: reuseId)
pinView!.image = UIImage(named:"pin")
pinView?.canShowCallout = true
pinView?.annotation
let button : UIButton = UIButton(type: UIButtonType.DetailDisclosure)
button.setImage(UIImage(named: "pin_arrow")?.imageWithRenderingMode(UIImageRenderingMode.AlwaysOriginal), forState:UIControlState.Normal)
pinView!.rightCalloutAccessoryView = button
let vw: UIView = UIView(frame: CGRectMake(0, 0, 40, 50))
let label: UILabel = UILabel(frame: CGRectMake(10, 0, 40, 50))
label.font = UIFont.init(name: "Roboto-Bold", size: 20)
label.textColor = UIColor(red:17/255.0, green:97/255.0, blue:172/255.0, alpha: 1.0)
label.numberOfLines = 1
for myObj in arrOfPinsOnMap where myObj.coordinate.latitude == pinView!.annotation!.coordinate.latitude && myObj.coordinate.longitude == pinView!.annotation!.coordinate.longitude && myObj.title == (pinView?.annotation?.title)!{
label.text = myObj.sale
if(myObj.sale != ""){
vw.addSubview(label)
if(label.text!.characters.count == 2){
vw.frame.size.width = 35
label.frame.size.width = 35
} else if(label.text!.characters.count == 3){
vw.frame.size.width = 47
label.frame.size.width = 47
} else if(label.text!.characters.count == 4){
label.frame.size.width = 67
vw.frame.size.width = 67
} else if(label.text!.characters.count > 4){
label.frame.size.width = 80
vw.frame.size.width = 80
}
pinView!.leftCalloutAccessoryView = vw
}
}
我有這種方法用於顯示引腳上的TAP之後的視圖。我可以在左側調整我的標籤大小,但標題保持固定大小。標題必須始終可見。
我的問題是不同的,但'var title:String? =「」'引發瞭如何解決我的問題的想法。對那個朋友+1。 – iUser