Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //
- // UIImageView+imageFrame.swift
- // Tindex
- //
- // Created by Koen Punt on 24-08-15.
- // Copyright (c) 2015 Koen Punt. All rights reserved.
- //
- import UIKit
- /** imageFrame Extends UIImageView
- */
- extension UIImageView {
- var imageSize: CGSize {
- get {
- if let image: UIImage = self.image {
- let widthRatio = image.size.width / self.frame.size.width
- let heightRatio = image.size.height / self.frame.size.height
- let ratio = maxElement([widthRatio, heightRatio])
- return CGSizeMake(image.size.width / ratio, image.size.height / ratio)
- }
- return CGSizeZero
- }
- }
- var imageFrame: CGRect {
- get {
- if let image: UIImage = self.image {
- let size = self.imageSize
- return CGRectMake((self.frame.size.width - size.width) / 2, (self.frame.size.height - size.height) / 2, size.width, size.height)
- }
- return CGRectZero
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement