Skip to content

Latest commit

 

History

History
37 lines (20 loc) · 814 Bytes

README.md

File metadata and controls

37 lines (20 loc) · 814 Bytes

UIImage+Frame

Extension (in Swift) and Category (in Obj-C) on UIImage with function that returns image frame in UIImageView based on current content mode. Playgound to play around included.

Supports all UIView.ContentModes. Will return CGRect.zero if image is not same as image view image.

Usage/Examples

Swift:

let image = UIImage(named: "my-image")
let imageView = UIImageView(image: image)

let frame = image.frame(in: imageView)

Obj-C:

UIImage *image = [UIImage imageNamed:@"my-image"];
UIImageView *imageView = [[UIImageView alloc] initWithImage:image];
    
CGRect frame = [image frameInView:imageView];

Screenshots

Playground

License

MIT