自定义MKA注释按钮 [英] Custom MKAnnotation button
问题描述
我想使用MKAnnotation
生成自定义注释.
I'd like to generate a custom annotation using MKAnnotation
.
annotationView?.image = UIImage(named: "annotation)") // this is to set the annotation image
annotationView?.leftCalloutAccessoryView = UIImageView(image: UIImage(named: "mySymbol")) // this is to add a icon left to the annotation UI
上面的几行工作正常,但是...现在,我想像上面的图片一样在注释"中添加自定义按钮.
The few lines above are working quiet well but ... now I'd like to add a custom button to the Annotation like in the image above.
到目前为止,使用默认选项是可行的:
Using the default one is working so far :
annotationView?.rightCalloutAccessoryView = UIButton(type: .detailDisclosure)
...但是不使用自定义按钮(只是不显示UI元素,仍然没有):
... but using a custom one is not (Just not showing a UI element, there is still NOTHING):
let myButton = UIButton(type: .custom)
myButton.setImage(UIImage(named: "myButton"), for: .normal)
annotationView?.rightCalloutAccessoryView = myButton
我不知道如何继续...我希望有人能够解决这个小问题.
I have no clue how to go on... I hope somebody is able to fix this small problem.
提前感谢,乔纳斯
推荐答案
我是提问者:-)
我自己找到了一个解决方案,没有创建一个完整的新视图-就像@Sh_Khan提到的那样-因为这仍然没有必要.
I found a solution on my own without creating a complete new view - like @Sh_Khan mentioned - because this is still not necessary.
这是我想出的:
let button = UIButton()
button.setImage(UIImage(named :"myIcon")?.withRenderingMode(.alwaysTemplate), for: .normal)
button.frame = CGRect(x: 0, y: 0, width: 50, height: 50)
annotationView?.rightCalloutAccessoryView = button
这篇关于自定义MKA注释按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!