I'd like to generate a custom annotation using MKAnnotation
.
![imgA](https://i.stack.imgur.com/fc4ol.png)
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
上面的几行运行得很好,但是......现在我想向注释添加一个自定义按钮,如上图所示。
到目前为止,使用默认的方法是有效的:
annotationView?.rightCalloutAccessoryView = UIButton(type: .detailDisclosure)
...但使用自定义的则不然(只是不显示 UI 元素,仍然存在NOTHING):
let myButton = UIButton(type: .custom)
myButton.setImage(UIImage(named: "myButton"), for: .normal)
annotationView?.rightCalloutAccessoryView = myButton
我不知道如何继续...我希望有人能够解决这个小问题。
提前致谢,乔纳斯
我是提问者:-)
我自己找到了解决方案无需创建完整的新视图- 就像@Sh_Khan 提到的 - 因为这仍然没有必要。
这就是我想出的:
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
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)