ios - 在 uiimageview 中具有边框的着色区域

标签 ios swift uiimageview uiimage

let templateImage = UIImage(named:"marker")?.withRenderingMode(.alwaysTemplate)
self.imageView.image = templateImage
self.imageView.contentMode = .scaleAspectFit
self.imageView?.tintColor = UIColor.red
self.imageView?.tintAdjustmentMode = .normal
self.imageView.backgroundColor = .clear

我使用的是 Swift 3

output screenshot

但我需要的是用黑色填充淡色区域边框,如下图所示:

expected result

标记图标在这里:

marker icon is here

最佳答案

您是否尝试为图像内容添加边框?如果是,那就不可能了。

您可以使用以下几行为 ImageView 添加边框:

self.imageView.layer.borderwidth = 1 //as per your requirement
self.imageView.layer.borderColor = UIColor. blackColor().CGColor

关于ios - 在 uiimageview 中具有边框的着色区域,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47586687/

相关文章:

iphone - Objective-C - UserDefaults 覆盖

ios - UISearchBar 使用时从 UINavigationBar 消失 "back swipe"iOS 12

ios - Spritekit - 每 10 点增加持续时间

iOS - 动画 - 图像从圆圈出来

ios - 使用imageView自定义navigationbar时存在Gap

ios - 在 if 条件下将 NSArray 变成 NSMutableArray

ios - UITableView - 将cornerRadius设置为图层不适用于顶角

ios - 当应用程序进入前台时,UITableViewCells 底部边缘闪烁

ios - 如何将安全区域添加到 View 高度?

ios - UIImagePickerController 与 ImageView