How to set corner radius of imageView?

后端 未结 10 666
清酒与你
清酒与你 2020-12-13 01:50

In Objective-C such line

self.mainImageView.layer.cornerRadius = CGRectGetWidth(self.mainImageView.frame)/4.0f;

does its job, I tried it in

10条回答
  •  轮回少年
    2020-12-13 02:40

    Marked with @IBInspectable in swift (or IBInspectable in Objective-C), they are easily editable in Interface Builder’s attributes inspector panel.
    You can directly set borderWidth,cornerRadius,borderColor in attributes inspector

    extension UIView {
    
      @IBInspectable var cornerRadius: CGFloat {
    
       get{
            return layer.cornerRadius
        }
        set {
            layer.cornerRadius = newValue
            layer.masksToBounds = newValue > 0
        }
      }
    
      @IBInspectable var borderWidth: CGFloat {
        get {
            return layer.borderWidth
        }
        set {
            layer.borderWidth = newValue
        }
      }
    
      @IBInspectable var borderColor: UIColor? {
        get {
            return UIColor(cgColor: layer.borderColor!)
        }
        set {
            layer.borderColor = borderColor?.cgColor
        }
      }
    }
    

提交回复
热议问题