Rounding UIImage and adding a border

前端 未结 9 1180
青春惊慌失措
青春惊慌失措 2020-12-09 18:19

so I want to show some pictures as annotations on the map. In order to do that I need to add the image property of the MKAnnotationView. I\'m using the regular images but I

9条回答
  •  青春惊慌失措
    2020-12-09 18:27

    you can create an IBDesignable class and set it to your Image. Then change properties in Storyboard with realtime changes

    @IBDesignable class CircularImageView: UIImageView {
    
    @IBInspectable var borderWidth : CGFloat {
        get { layer.borderWidth }
        set {
            layer.masksToBounds = true
            layer.borderWidth = newValue
            layer.cornerRadius = frame.size.width / 2
        }
    }
    
    @IBInspectable var borderColor: UIColor? {
        set {
            guard let uiColor = newValue else { return }
            layer.borderColor = uiColor.cgColor
        }
        get {
            guard let color = layer.borderColor else { return nil }
            return UIColor(cgColor: color)
        }
    }
    
    }
    

提交回复
热议问题