Skip to content

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

License

Notifications You must be signed in to change notification settings

niczyja/UIImage-Frame

Repository files navigation

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

About

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

Topics

Resources

License

Stars

Watchers

Forks