Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Insets to UIImageView?

I would like to achieve :

  • Scale to fill mode of image view
  • Insets to UIImageView so that image does not meet the edges of the UIImageView

Bottomline: I want to increase the touch area of the UIImageView without stretching the image beyond certain size.

Is it possible through storyboard ? If not can anyone tell how to do it programmatically ?

I can achieve similar functionality through a UIButton and setting image inset through storyboard but I can't find any such thing with UIImageView.

like image 279
Sarasranglt Avatar asked Aug 31 '15 05:08

Sarasranglt


1 Answers

You can add inset to UIImage instead of UIImageView.

Swift 4

let imageView = UIImageView()  imageView.contentMode = .scaleAspectFill imageView.image = UIImage(named: "example")?.withAlignmentRectInsets(UIEdgeInsets(top: -4, left: 0, bottom: -4, right: 0)) 
like image 99
BumMo Koo Avatar answered Sep 19 '22 22:09

BumMo Koo