Rect size for image size based imageView iOS swift

 Solution:


extension UIImageView {

  

  var contentClippRectCGRect {

    var imageRect:CGRect!

    let scaleX = bounds.size.width/image!.size.width

    let scaleY = bounds.size.height/image!.size.height

    if scaleX < scaleY {

      imageRect = CGRect(x: 0, y: (bounds.size.height - scaleX*image!.size.height)*0.5, width: bounds.size.width, height: scaleX*image!.size.height)


    }

    else {

      imageRect = CGRect(x:(bounds.size.width-scaleY*image!.size.width)*0.5, y:0, width: scaleY*image!.size.width, height: scaleX*image!.size.height)

  }

    return imageRect

  }

  

}


Comments

Popular posts from this blog

Invalid bundle error while upload the app to the app Store

store cgpoint in userdefaults iOS swift