@H_502_8@
我已经使用自定义detailCalloutAccessoryVIEw实现了一个自定义标注气泡,里面有两个标签.@H_502_8@
我知道如何用这一行改变detailCalloutAccessoryVIEw的颜色.@H_502_8@
@H_502_8@
vIEw.detailCalloutAccessoryVIEw?.backgroundcolor = UIcolor.red
但我无法弄清楚如何改变主气泡的背景颜色(现在它是透明的灰色/白色).使用vIEw.detailCalloutAccessoryVIEw?.backgroundcolor = UIcolor.red行我的calloutbubble看起来像这样:@H_502_8@
@H_502_8@但我希望我的自定义气泡看起来像这样:@H_502_8@
@H_502_8@这是我的vIEwFor注释方法:@H_502_8@
@H_502_8@
func mapVIEw(_ mapVIEw: MKMapVIEw,vIEwFor annotation: MKAnnotation) -> MKAnnotationVIEw? { if annotation is MKUserLocation { return nil } let IDentifIEr = "pin" var vIEw : MKAnnotationVIEw if let dequedVIEw = mapVIEw.dequeueReusableAnnotationVIEw(withIDentifIEr: IDentifIEr) { dequedVIEw.annotation = annotation vIEw = dequedVIEw } else { vIEw = MKAnnotationVIEw(annotation: annotation,reuseIDentifIEr: IDentifIEr) vIEw.canShowCallout = true } let pinImage = UIImage.init(named: "customPin") dispatchQueue.main.async(execute: { vIEw.detailCalloutAccessoryVIEw?.backgroundcolor = UIcolor.red }) vIEw.image = pinImage configureDetailVIEw(annotationVIEw: vIEw) return vIEw }
我在Xcode 8 w / Swift 3中工作.@H_502_8@
知道如何将标题的字体类型和默认黑色从黑色更改为另一种颜色也很有趣.
在详细视图中,我可以轻松更改xib文件中自定义标签的颜色,但不知道如何访问默认标题属性.@H_502_8@解决方法 我已根据您的要求创建了代码,请在下面的网址下载代码并进行审核.
@H_502_8@
链接:https://www.dropbox.com/s/o2howwqceq8rsgu/MapInformation.zip?dl=0@H_502_8@
@H_502_8@
Environment : Xcode 8 and Swift3@H_502_8@
突出显示我已完成的代码.@H_502_8@
我采用的方法是显示Popup(UIPresentationController)而不是callout.有关更多信息,请查看以下代码.@H_502_8@
A)我曾使用UIbutton在MapVIEw上显示注释,并在用户点击它时显示d出窗口.@H_502_8@
@H_502_8@
func mapVIEw(_ mapVIEw: MKMapVIEw,vIEwFor annotation: MKAnnotation) -> MKAnnotationVIEw? { if annotation is MKUserLocation { return nil } let IDentifIEr = "pin" var annotationVIEw = self.mapVIEw.dequeueReusableAnnotationVIEw(withIDentifIEr: IDentifIEr) as! AnnotationVIEw? if annotationVIEw == nil { annotationVIEw = AnnotationVIEw(annotation: annotation,reuseIDentifIEr: IDentifIEr) annotationVIEw?.canShowCallout = false } else { annotationVIEw?.annotation = annotation } //Take the UIbutton and implement the touchupinsIDe action for showing the popup. let pinImage = UIImage.init(named: "customPin") annotationVIEw?.frame = CGRect(x: 0,y: 0,wIDth: (pinImage?.size.wIDth)!,height: (pinImage?.size.wIDth)!) annotationVIEw?.mapPin = UIbutton(frame: (annotationVIEw?.frame)!); annotationVIEw?.mapPin.addTarget(self,action: #selector(VIEwController.showPopup(sender:)),for: .touchUpInsIDe) annotationVIEw?.addSubvIEw((annotationVIEw?.mapPin)!) annotationVIEw?.mapPin.setimage(pinImage,for: .normal) return annotationVIEw }
B)当用户点击注释时显示d出窗口.@H_502_8@
@H_502_8@
func showPopup(sender: UIbutton!) { let popupVC = self.storyboard?.instantiateVIEwController(withIDentifIEr: "Popup") as? Popup popupVC?.preferredContentSize = CGSize(wIDth: 250,height: 150) popupVC?.modalPresentationStyle = UIModalPresentationStyle.popover let rect = sender.supervIEw?.convert(sender.frame,to: self.vIEw) popupVC?.popoverPresentationController?.delegate = self; popupVC?.popoverPresentationController?.sourceVIEw = self.vIEw popupVC?.popoverPresentationController?.sourceRect = rect! popupVC?.popoverPresentationController?.backgroundcolor = UIcolor.red self.present(popupVC!,animated: true,completion: nil) }
注意@H_502_8@
@H_502_8@
If you want to change the popup color from red to other different
color then you can do only single line of Coding by changing the color name.@H_502_8@popupVC?.popoverPresentationController?.backgroundcolor = UIcolor.red@H_502_8@
请看下面的截图.@H_502_8@
@H_502_8@ 总结以上是内存溢出为你收集整理的swift – 如何使用detailCalloutAccessoryView更改标注气泡的默认背景颜色全部内容,希望文章能够帮你解决swift – 如何使用detailCalloutAccessoryView更改标注气泡的默认背景颜色所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)