所以我想在 map 上显示一些图片作为注释。为此,我需要添加MKAnnotationView的image属性。我使用的是常规图像,但我希望它们经过圆角处理并带有边框。因此,我找到了一种修整UIImage的方法,并且找到了向UIImage添加边框的方法,但是似乎没有添加边框(我实际上没有在屏幕上显示图像,也许是问题所在?)。

我使用了https://stackoverflow.com/a/29047372/4665643这个答案,对border做了一些修改。即:

imageView.layer.borderWidth = 1.5
imageView.layer.borderColor = UIColor.whiteColor().CGColor
imageView.clipsToBounds = true

但是我在 map 上的图像没有任何边框。有什么建议 ?

最佳答案

imageView.layer.masksToBounds = true
imageView.layer.borderWidth = 1.5
imageView.layer.borderColor = UIColor.white.cgColor
imageView.layer.cornerRadius = imageView.bounds.width / 2

尝试这个。

07-28 01:53
查看更多